
<!doctype html>
<html lang="zh" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      
        <link rel="prev" href="../Development_Manual/">
      
      
        <link rel="next" href="../CMSIS_RTOS_API_Use_Guide/">
      
      <link rel="icon" href="../../assets/favicon.png">
      <meta name="generator" content="mkdocs-1.4.3, mkdocs-material-9.1.19">
    
    
      
        <title>TobudOS内核API参考手册 - TobudOS Documentation</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/main.eebd395e.min.css">
      
        
        <link rel="stylesheet" href="../../assets/stylesheets/palette.ecc896b0.min.css">
      
      

    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
    <script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#tobudos-api" class="md-skip">
          跳转至
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="页眉">
    <a href="../.." title="TobudOS Documentation" class="md-header__button md-logo" aria-label="TobudOS Documentation" data-md-component="logo">
      
  <img src="../../assets/logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            TobudOS Documentation
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              TobudOS内核API参考手册
            
          </span>
        </div>
      </div>
    </div>
    
      
        <form class="md-header__option" data-md-component="palette">
          
            
            
            
            <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
            
              <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
            
            
            
            <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
            
              <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
        </form>
      
    
    
      <div class="md-header__option">
        <div class="md-select">
          
          <button class="md-header__button md-icon" aria-label="选择当前语言">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m12.87 15.07-2.54-2.51.03-.03A17.52 17.52 0 0 0 14.07 6H17V4h-7V2H8v2H1v2h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04M18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12m-2.62 7 1.62-4.33L19.12 17h-3.24Z"/></svg>
          </button>
          <div class="md-select__inner">
            <ul class="md-select__list">
              
                <li class="md-select__item">
                  <a href="./" hreflang="zh" class="md-select__link">
                    中文
                  </a>
                </li>
              
                <li class="md-select__item">
                  <a href="../../en/DevelopGuide/API_Reference/" hreflang="en" class="md-select__link">
                    English
                  </a>
                </li>
              
            </ul>
          </div>
        </div>
      </div>
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="搜索" placeholder="搜索" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="查找">
        
          <a href="javascript:void(0)" class="md-search__icon md-icon" title="分享" aria-label="分享" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7 0-.24-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91 1.61 0 2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08Z"/></svg>
          </a>
        
        <button type="reset" class="md-search__icon md-icon" title="清空当前内容" aria-label="清空当前内容" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
        </button>
      </nav>
      
        <div class="md-search__suggest" data-md-component="search-suggest"></div>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            正在初始化搜索引擎
          </div>
          <ol class="md-search-result__list" role="presentation"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://atomgit.com/tobudos/Document" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
  </div>
  <div class="md-source__repository">
    Atomgit
  </div>
</a>
      </div>
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
            
<nav class="md-tabs" aria-label="标签" data-md-component="tabs">
  <div class="md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  <li class="md-tabs__item">
    <a href="../.." class="md-tabs__link">
      首页
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../Introduction/TobudOS_Brief_Introduction/" class="md-tabs__link">
      项目特性简介
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_KEIL/" class="md-tabs__link">
        内核移植指南
      </a>
    </li>
  

      
        
  
  
    
  


  
  
  
    <li class="md-tabs__item">
      <a href="../Development_Manual/" class="md-tabs__link md-tabs__link--active">
        内核开发指南
      </a>
    </li>
  

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../AT_Framwork_Guide/AT_Firmware_and_SAL_Firmware_User_Guide/" class="md-tabs__link">
        AT模组框架
      </a>
    </li>
  

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../ElfLoader_Guide/ElfLoader_Quick_Start/" class="md-tabs__link">
      ElfLoader动态加载
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../OTA_Guide/OTA_Quick_Start_based_EVB_MX_Plus/" class="md-tabs__link">
        固件升级
      </a>
    </li>
  

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../MicroPython_Guide/BearPi_MicroPython_QuickStart/" class="md-tabs__link">
      MicroPython开发指南
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../VFS_Guide/vfs/" class="md-tabs__link">
      文件系统
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../GUI_Guide/gui/" class="md-tabs__link">
      GUI开发
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../DevelopKit/1.EVB_MX_Plus_Quick_Start/" class="md-tabs__link">
        官方开发套件
      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="导航栏" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../.." title="TobudOS Documentation" class="md-nav__button md-logo" aria-label="TobudOS Documentation" data-md-component="logo">
      
  <img src="../../assets/logo.png" alt="logo">

    </a>
    TobudOS Documentation
  </label>
  
    <div class="md-nav__source">
      <a href="https://atomgit.com/tobudos/Document" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
  </div>
  <div class="md-source__repository">
    Atomgit
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../.." class="md-nav__link">
        首页
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../Introduction/TobudOS_Brief_Introduction/" class="md-nav__link">
        项目特性简介
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
      
      
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
          内核移植指南
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_3">
          <span class="md-nav__icon md-icon"></span>
          内核移植指南
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_KEIL/" class="md-nav__link">
        基于Keil移植TobudOS内核
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_IAR/" class="md-nav__link">
        基于IAR 移植TobudOS内核
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_GCC/" class="md-nav__link">
        基于GCC 移植TobudOS内核
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
    
  
  
    
    <li class="md-nav__item md-nav__item--active md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" checked>
      
      
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
          内核开发指南
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="true">
        <label class="md-nav__title" for="__nav_4">
          <span class="md-nav__icon md-icon"></span>
          内核开发指南
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../Development_Manual/" class="md-nav__link">
        TobudOS内核开发指南
      </a>
    </li>
  

            
          
            
              
  
  
    
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
        
      
      
      <a href="./" class="md-nav__link md-nav__link--active">
        TobudOS内核API参考手册
      </a>
      
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../CMSIS_RTOS_API_Use_Guide/" class="md-nav__link">
        TobudOS内核CMSIS适配API指南
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
      
      
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
          AT模组框架
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_5">
          <span class="md-nav__icon md-icon"></span>
          AT模组框架
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../AT_Framwork_Guide/AT_Firmware_and_SAL_Firmware_User_Guide/" class="md-nav__link">
        无线通信模组AT框架开发指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../AT_Framwork_Guide/How_To_Use_Esp8266_Tencent_Firmware_Connect_Iot_Explorer/" class="md-nav__link">
        基于AT框架和定制模组如何对接腾讯云IoT Explorer平台
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../ElfLoader_Guide/ElfLoader_Quick_Start/" class="md-nav__link">
        ElfLoader动态加载
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" >
      
      
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0">
          固件升级
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_7">
          <span class="md-nav__icon md-icon"></span>
          固件升级
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../OTA_Guide/OTA_Quick_Start_based_EVB_MX_Plus/" class="md-nav__link">
        基于EVB_MX的固件升级指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../OTA_Guide/In_Application_Programming_based_EVB_MX_Plus/" class="md-nav__link">
        基于EVB_MX的IAP开发指南
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../MicroPython_Guide/BearPi_MicroPython_QuickStart/" class="md-nav__link">
        MicroPython开发指南
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../VFS_Guide/vfs/" class="md-nav__link">
        文件系统
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../GUI_Guide/gui/" class="md-nav__link">
        GUI开发
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_11" >
      
      
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_11" id="__nav_11_label" tabindex="0">
          官方开发套件
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_11_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_11">
          <span class="md-nav__icon md-icon"></span>
          官方开发套件
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/1.EVB_MX_Plus_Quick_Start/" class="md-nav__link">
        EVB_MX+（STM32L4）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/2.EVB_LX_RISC-V_Quick_Start/" class="md-nav__link">
        EVB_LX（GD32V RISC-V）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/3.EVB_WL_Quick_Start/" class="md-nav__link">
        EVB_WL（STM32WL）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/4.EVB_G0_QuickStart/" class="md-nav__link">
        EVB_G0（STM32G0）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/5.EVB_AIoT_NXP_QuickStart/" class="md-nav__link">
        EVB_AIoT_NXP（RT1062）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/6.EVB_CH32V_QuickStart/" class="md-nav__link">
        EVB_CH32V（CH32V307）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/7.EVB_AIoT_STM32_QuickStart/" class="md-nav__link">
        EVB_AIoT_STM32（STM32H7）快速上手
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    
  
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  

  
    <a href="https://atomgit.com/tobudos/Document/edit/master/docs/DevelopGuide/API_Reference.md" title="编辑此页" class="md-content__button md-icon">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
    </a>
  
  
    
      
    
    <a href="https://atomgit.com/tobudos/Document/raw/master/docs/DevelopGuide/API_Reference.md" title="查看本页的源代码" class="md-content__button md-icon">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3m0 8a5 5 0 0 1-5-5 5 5 0 0 1 5-5 5 5 0 0 1 5 5 5 5 0 0 1-5 5m0-12.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5Z"/></svg>
    </a>
  


<h1 id="tobudos-api">TobudOS API指南文档</h1>
<div class="toc">
<ul>
<li><a href="#tobudos-api">TobudOS API指南文档</a></li>
<li><a href="#api">内核 API</a><ul>
<li><a href="#_1">系统管理</a><ul>
<li><a href="#tos_knl_init">tos_knl_init</a></li>
<li><a href="#tos_knl_start">tos_knl_start</a></li>
<li><a href="#tos_knl_is_running">tos_knl_is_running</a></li>
<li><a href="#tos_knl_irq_enter">tos_knl_irq_enter</a></li>
<li><a href="#tos_knl_irq_leave">tos_knl_irq_leave</a></li>
<li><a href="#tos_knl_sched_lock">tos_knl_sched_lock</a></li>
<li><a href="#tos_knl_sched_unlock">tos_knl_sched_unlock</a></li>
</ul>
</li>
<li><a href="#_2">任务管理</a><ul>
<li><a href="#tos_task_create">tos_task_create</a></li>
<li><a href="#tos_task_create_dyn">tos_task_create_dyn</a></li>
<li><a href="#tos_task_destroy">tos_task_destroy</a></li>
<li><a href="#tos_task_destroy_dyn">tos_task_destroy_dyn</a></li>
<li><a href="#tos_task_delay">tos_task_delay</a></li>
<li><a href="#tos_task_delay_abort">tos_task_delay_abort</a></li>
<li><a href="#tos_task_suspend">tos_task_suspend</a></li>
<li><a href="#tos_task_resume">tos_task_resume</a></li>
<li><a href="#tos_task_prio_change">tos_task_prio_change</a></li>
<li><a href="#tos_task_yield">tos_task_yield</a></li>
<li><a href="#tos_task_stack_draught_depth">tos_task_stack_draught_depth</a></li>
<li><a href="#tos_task_curr_task_get">tos_task_curr_task_get</a></li>
<li><a href="#tos_task_walkthru">tos_task_walkthru</a></li>
</ul>
</li>
<li><a href="#_3">堆内存管理</a><ul>
<li><a href="#tos_mmheap_pool_add">tos_mmheap_pool_add</a></li>
<li><a href="#tos_mmheap_pool_rmv">tos_mmheap_pool_rmv</a></li>
<li><a href="#tos_mmheap_alloc">tos_mmheap_alloc</a></li>
<li><a href="#tos_mmheap_aligned_alloc">tos_mmheap_aligned_alloc</a></li>
<li><a href="#tos_mmheap_realloc">tos_mmheap_realloc</a></li>
<li><a href="#tos_mmheap_free">tos_mmheap_free</a></li>
<li><a href="#tos_mmheap_pool_check">tos_mmheap_pool_check</a></li>
<li><a href="#tos_mmheap_check">tos_mmheap_check</a></li>
</ul>
</li>
<li><a href="#_4">块内存管理</a><ul>
<li><a href="#tos_mmblk_pool_create">tos_mmblk_pool_create</a></li>
<li><a href="#tos_mmblk_alloc">tos_mmblk_alloc</a></li>
<li><a href="#tos_mmblk_free">tos_mmblk_free</a></li>
</ul>
</li>
<li><a href="#mutex">互斥量 mutex</a><ul>
<li><a href="#tos_mutex_create">tos_mutex_create</a></li>
<li><a href="#tos_mutex_destroy">tos_mutex_destroy</a></li>
<li><a href="#tos_mutex_pend">tos_mutex_pend</a></li>
<li><a href="#tos_mutex_pend_timed">tos_mutex_pend_timed</a></li>
<li><a href="#tos_mutex_post">tos_mutex_post</a></li>
</ul>
</li>
<li><a href="#semaphore">信号量 semaphore</a><ul>
<li><a href="#tos_sem_create">tos_sem_create</a></li>
<li><a href="#tos_sem_create_max">tos_sem_create_max</a></li>
<li><a href="#tos_sem_destroy">tos_sem_destroy</a></li>
<li><a href="#tos_sem_pend">tos_sem_pend</a></li>
<li><a href="#tos_sem_post">tos_sem_post</a></li>
<li><a href="#tos_sem_post_all">tos_sem_post_all</a></li>
</ul>
</li>
<li><a href="#event">事件 event</a><ul>
<li><a href="#tos_event_create">tos_event_create</a></li>
<li><a href="#tos_event_destroy">tos_event_destroy</a></li>
<li><a href="#tos_event_pend">tos_event_pend</a></li>
<li><a href="#tos_event_post">tos_event_post</a></li>
<li><a href="#tos_event_post_keep">tos_event_post_keep</a></li>
</ul>
</li>
<li><a href="#completion">完成量 completion</a><ul>
<li><a href="#tos_completion_create">tos_completion_create</a></li>
<li><a href="#tos_completion_destroy">tos_completion_destroy</a></li>
<li><a href="#tos_completion_pend">tos_completion_pend</a></li>
<li><a href="#tos_completion_pend_timed">tos_completion_pend_timed</a></li>
<li><a href="#tos_completion_post">tos_completion_post</a></li>
<li><a href="#tos_completion_post_all">tos_completion_post_all</a></li>
<li><a href="#tos_completion_reset">tos_completion_reset</a></li>
<li><a href="#tos_completion_is_done">tos_completion_is_done</a></li>
</ul>
</li>
<li><a href="#countdown-latch">计数锁 countdown latch</a><ul>
<li><a href="#tos_countdownlatch_create">tos_countdownlatch_create</a></li>
<li><a href="#tos_countdownlatch_destroy">tos_countdownlatch_destroy</a></li>
<li><a href="#tos_countdownlatch_pend">tos_countdownlatch_pend</a></li>
<li><a href="#tos_countdownlatch_pend_timed">tos_countdownlatch_pend_timed</a></li>
<li><a href="#tos_countdownlatch_post">tos_countdownlatch_post</a></li>
<li><a href="#tos_countdownlatch_reset">tos_countdownlatch_reset</a></li>
</ul>
</li>
<li><a href="#barrier">栅栏 barrier</a><ul>
<li><a href="#tos_barrier_create">tos_barrier_create</a></li>
<li><a href="#tos_barrier_destroy">tos_barrier_destroy</a></li>
<li><a href="#tos_barrier_pend">tos_barrier_pend</a></li>
<li><a href="#tos_barrier_reset">tos_barrier_reset</a></li>
</ul>
</li>
<li><a href="#rwlock">读写锁 rwlock</a><ul>
<li><a href="#tos_rwlock_create">tos_rwlock_create</a></li>
<li><a href="#tos_rwlock_destroy">tos_rwlock_destroy</a></li>
<li><a href="#tos_rwlock_rpend_timed">tos_rwlock_rpend_timed</a></li>
<li><a href="#tos_rwlock_rpend">tos_rwlock_rpend</a></li>
<li><a href="#tos_rwlock_rpend_try">tos_rwlock_rpend_try</a></li>
<li><a href="#tos_rwlock_wpend_timed">tos_rwlock_wpend_timed</a></li>
<li><a href="#tos_rwlock_wpend">tos_rwlock_wpend</a></li>
<li><a href="#tos_rwlock_wpend_try">tos_rwlock_wpend_try</a></li>
<li><a href="#tos_rwlock_rpost">tos_rwlock_rpost</a></li>
<li><a href="#tos_rwlock_wpost">tos_rwlock_wpost</a></li>
<li><a href="#tos_rwlock_post">tos_rwlock_post</a></li>
</ul>
</li>
<li><a href="#message-queue">消息队列 message queue</a><ul>
<li><a href="#tos_msg_q_create">tos_msg_q_create</a></li>
<li><a href="#tos_msg_q_create_dyn">tos_msg_q_create_dyn</a></li>
<li><a href="#tos_msg_q_destroy">tos_msg_q_destroy</a></li>
<li><a href="#tos_msg_q_destroy_dyn">tos_msg_q_destroy_dyn</a></li>
<li><a href="#tos_msg_q_flush">tos_msg_q_flush</a></li>
<li><a href="#tos_msg_q_pend">tos_msg_q_pend</a></li>
<li><a href="#tos_msg_q_post">tos_msg_q_post</a></li>
<li><a href="#tos_msg_q_post_all">tos_msg_q_post_all</a></li>
</ul>
</li>
<li><a href="#mail-queue">邮箱队列 mail queue</a><ul>
<li><a href="#tos_mail_q_create">tos_mail_q_create</a></li>
<li><a href="#tos_mail_q_create_dyn">tos_mail_q_create_dyn</a></li>
<li><a href="#tos_mail_q_destroy">tos_mail_q_destroy</a></li>
<li><a href="#tos_mail_q_destroy_dyn">tos_mail_q_destroy_dyn</a></li>
<li><a href="#tos_mail_q_flush">tos_mail_q_flush</a></li>
<li><a href="#tos_mail_q_pend">tos_mail_q_pend</a></li>
<li><a href="#tos_mail_q_post">tos_mail_q_post</a></li>
<li><a href="#tos_mail_q_post_all">tos_mail_q_post_all</a></li>
</ul>
</li>
<li><a href="#priority-message-queue">优先级消息队列 priority message queue</a><ul>
<li><a href="#tos_prio_msg_q_create">tos_prio_msg_q_create</a></li>
<li><a href="#tos_prio_msg_q_create_dyn">tos_prio_msg_q_create_dyn</a></li>
<li><a href="#tos_prio_msg_q_destroy">tos_prio_msg_q_destroy</a></li>
<li><a href="#tos_prio_msg_q_destroy_dyn">tos_prio_msg_q_destroy_dyn</a></li>
<li><a href="#tos_prio_msg_q_flush">tos_prio_msg_q_flush</a></li>
<li><a href="#tos_prio_msg_q_pend">tos_prio_msg_q_pend</a></li>
<li><a href="#tos_prio_msg_q_post">tos_prio_msg_q_post</a></li>
<li><a href="#tos_prio_msg_q_post_all">tos_prio_msg_q_post_all</a></li>
</ul>
</li>
<li><a href="#priority-mail-queue">优先级邮箱队列 priority mail queue</a><ul>
<li><a href="#tos_prio_mail_q_create">tos_prio_mail_q_create</a></li>
<li><a href="#tos_prio_mail_q_create_dyn">tos_prio_mail_q_create_dyn</a></li>
<li><a href="#tos_prio_mail_q_destroy">tos_prio_mail_q_destroy</a></li>
<li><a href="#tos_prio_mail_q_destroy_dyn">tos_prio_mail_q_destroy_dyn</a></li>
<li><a href="#tos_prio_mail_q_flush">tos_prio_mail_q_flush</a></li>
<li><a href="#tos_prio_mail_q_pend">tos_prio_mail_q_pend</a></li>
<li><a href="#tos_prio_mail_q_post">tos_prio_mail_q_post</a></li>
<li><a href="#tos_prio_mail_q_post_all">tos_prio_mail_q_post_all</a></li>
</ul>
</li>
<li><a href="#ring-queue">环形队列 ring queue</a><ul>
<li><a href="#tos_ring_q_create">tos_ring_q_create</a></li>
<li><a href="#tos_ring_q_create_dyn">tos_ring_q_create_dyn</a></li>
<li><a href="#tos_ring_q_destroy">tos_ring_q_destroy</a></li>
<li><a href="#tos_ring_q_destroy_dyn">tos_ring_q_destroy_dyn</a></li>
<li><a href="#tos_ring_q_enqueue">tos_ring_q_enqueue</a></li>
<li><a href="#tos_ring_q_dequeue">tos_ring_q_dequeue</a></li>
<li><a href="#tos_ring_q_flush">tos_ring_q_flush</a></li>
<li><a href="#tos_ring_q_is_empty">tos_ring_q_is_empty</a></li>
<li><a href="#tos_ring_q_is_full">tos_ring_q_is_full</a></li>
</ul>
</li>
<li><a href="#fifo">字符流先入先出队列 fifo</a><ul>
<li><a href="#tos_chr_fifo_create">tos_chr_fifo_create</a></li>
<li><a href="#tos_chr_fifo_create_dyn">tos_chr_fifo_create_dyn</a></li>
<li><a href="#tos_chr_fifo_destroy">tos_chr_fifo_destroy</a></li>
<li><a href="#tos_chr_fifo_destroy_dyn">tos_chr_fifo_destroy_dyn</a></li>
<li><a href="#tos_chr_fifo_push">tos_chr_fifo_push</a></li>
<li><a href="#tos_chr_fifo_push_stream">tos_chr_fifo_push_stream</a></li>
<li><a href="#tos_chr_fifo_pop">tos_chr_fifo_pop</a></li>
<li><a href="#tos_chr_fifo_pop_stream">tos_chr_fifo_pop_stream</a></li>
<li><a href="#tos_chr_fifo_flush">tos_chr_fifo_flush</a></li>
<li><a href="#tos_chr_fifo_is_empty">tos_chr_fifo_is_empty</a></li>
<li><a href="#tos_chr_fifo_is_full">tos_chr_fifo_is_full</a></li>
</ul>
</li>
<li><a href="#binary-heap">二项堆 binary heap</a><ul>
<li><a href="#tos_bin_heap_create">tos_bin_heap_create</a></li>
<li><a href="#tos_bin_heap_create_dyn">tos_bin_heap_create_dyn</a></li>
<li><a href="#tos_bin_heap_destroy">tos_bin_heap_destroy</a></li>
<li><a href="#tos_bin_heap_destroy_dyn">tos_bin_heap_destroy_dyn</a></li>
<li><a href="#tos_bin_heap_push">tos_bin_heap_push</a></li>
<li><a href="#tos_bin_heap_pop">tos_bin_heap_pop</a></li>
<li><a href="#tos_bin_heap_flush">tos_bin_heap_flush</a></li>
<li><a href="#tos_bin_heap_is_empty">tos_bin_heap_is_empty</a></li>
<li><a href="#tos_bin_heap_is_full">tos_bin_heap_is_full</a></li>
</ul>
</li>
<li><a href="#priority-queue">优先级队列 priority queue</a><ul>
<li><a href="#tos_prio_q_create">tos_prio_q_create</a></li>
<li><a href="#tos_prio_q_create_dyn">tos_prio_q_create_dyn</a></li>
<li><a href="#tos_prio_q_destroy">tos_prio_q_destroy</a></li>
<li><a href="#tos_prio_q_destroy_dyn">tos_prio_q_destroy_dyn</a></li>
<li><a href="#tos_prio_q_enqueue">tos_prio_q_enqueue</a></li>
<li><a href="#tos_prio_q_dequeue">tos_prio_q_dequeue</a></li>
<li><a href="#tos_prio_q_flush">tos_prio_q_flush</a></li>
<li><a href="#tos_prio_q_is_empty">tos_prio_q_is_empty</a></li>
<li><a href="#tos_prio_q_is_full">tos_prio_q_is_full</a></li>
</ul>
</li>
<li><a href="#timer">定时器 timer</a><ul>
<li><a href="#tos_timer_create">tos_timer_create</a></li>
<li><a href="#tos_timer_destroy">tos_timer_destroy</a></li>
<li><a href="#tos_timer_start">tos_timer_start</a></li>
<li><a href="#tos_timer_stop">tos_timer_stop</a></li>
<li><a href="#tos_timer_delay_change">tos_timer_delay_change</a></li>
<li><a href="#tos_timer_period_change">tos_timer_period_change</a></li>
</ul>
</li>
<li><a href="#stopwatch">计时表 stopwatch</a><ul>
<li><a href="#tos_stopwatch_create">tos_stopwatch_create</a></li>
<li><a href="#tos_stopwatch_destroy">tos_stopwatch_destroy</a></li>
<li><a href="#tos_stopwatch_countdown">tos_stopwatch_countdown</a></li>
<li><a href="#tos_stopwatch_countdown_ms">tos_stopwatch_countdown_ms</a></li>
<li><a href="#tos_stopwatch_delay">tos_stopwatch_delay</a></li>
<li><a href="#tos_stopwatch_delay_ms">tos_stopwatch_delay_ms</a></li>
<li><a href="#tos_stopwatch_remain">tos_stopwatch_remain</a></li>
<li><a href="#tos_stopwatch_remain_ms">tos_stopwatch_remain_ms</a></li>
<li><a href="#tos_stopwatch_is_expired">tos_stopwatch_is_expired</a></li>
</ul>
</li>
<li><a href="#bitmap">位图 bitmap</a><ul>
<li><a href="#tos_bitmap_create_empty">tos_bitmap_create_empty</a></li>
<li><a href="#tos_bitmap_create_full">tos_bitmap_create_full</a></li>
<li><a href="#tos_bitmap_destroy">tos_bitmap_destroy</a></li>
<li><a href="#tos_bitmap_set">tos_bitmap_set</a></li>
<li><a href="#tos_bitmap_reset">tos_bitmap_reset</a></li>
<li><a href="#tos_bitmap_is_set">tos_bitmap_is_set</a></li>
<li><a href="#tos_bitmap_is_reset">tos_bitmap_is_reset</a></li>
<li><a href="#tos_bitmap_lsb">tos_bitmap_lsb</a></li>
</ul>
</li>
<li><a href="#_5">时间管理</a><ul>
<li><a href="#tos_systick_get">tos_systick_get</a></li>
<li><a href="#tos_systick_set">tos_systick_set</a></li>
<li><a href="#tos_tick2millisec">tos_tick2millisec</a></li>
<li><a href="#tos_millisec2tick">tos_millisec2tick</a></li>
<li><a href="#tos_sleep_ms">tos_sleep_ms</a></li>
<li><a href="#tos_sleep_hmsm">tos_sleep_hmsm</a></li>
</ul>
</li>
<li><a href="#_6">功耗管理</a><ul>
<li><a href="#tos_pm_cpu_lpwr_mode_set">tos_pm_cpu_lpwr_mode_set</a></li>
<li><a href="#tos_pm_device_register">tos_pm_device_register</a></li>
<li><a href="#tos_tickless_wkup_alarm_install">tos_tickless_wkup_alarm_install</a></li>
<li><a href="#tos_tickless_wkup_alarm_init">tos_tickless_wkup_alarm_init</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#api_1">组件 API</a><ul>
<li><a href="#mqtt">MQTT 端云对接</a><ul>
<li><a href="#tos_mqtt_connect">tos_mqtt_connect</a></li>
<li><a href="#tos_mqtt_publish">tos_mqtt_publish</a></li>
<li><a href="#tos_mqtt_subscribe">tos_mqtt_subscribe</a></li>
<li><a href="#tos_mqtt_receive">tos_mqtt_receive</a></li>
</ul>
</li>
<li><a href="#cmsis">CMSIS 适配层</a><ul>
<li><a href="#oskernelstart">osKernelStart</a></li>
<li><a href="#oskernelinitialize">osKernelInitialize</a></li>
<li><a href="#oskernelrunning">osKernelRunning</a></li>
<li><a href="#oskernelsystick">osKernelSysTick</a></li>
<li><a href="#osthreadcreate">osThreadCreate</a></li>
<li><a href="#osthreadgetid">osThreadGetId</a></li>
<li><a href="#osthreadterminate">osThreadTerminate</a></li>
<li><a href="#osthreadsetpriority">osThreadSetPriority</a></li>
<li><a href="#osthreadgetpriority">osThreadGetPriority</a></li>
<li><a href="#osdelay">osDelay</a></li>
<li><a href="#ostimercreate">osTimerCreate</a></li>
<li><a href="#ostimerstart">osTimerStart</a></li>
<li><a href="#ostimerstop">osTimerStop</a></li>
<li><a href="#ostimerdelete">osTimerDelete</a></li>
<li><a href="#osmutexcreate">osMutexCreate</a></li>
<li><a href="#osmutexwait">osMutexWait</a></li>
<li><a href="#osmutexrelease">osMutexRelease</a></li>
<li><a href="#osmutexdelete">osMutexDelete</a></li>
<li><a href="#ossemaphorecreate">osSemaphoreCreate</a></li>
<li><a href="#ossemaphorewait">osSemaphoreWait</a></li>
<li><a href="#ossemaphorerelease">osSemaphoreRelease</a></li>
<li><a href="#ossemaphoredelete">osSemaphoreDelete</a></li>
<li><a href="#ospoolcreate">osPoolCreate</a></li>
<li><a href="#ospoolalloc">osPoolAlloc</a></li>
<li><a href="#ospoolcalloc">osPoolCAlloc</a></li>
<li><a href="#ospoolfree">osPoolFree</a></li>
<li><a href="#osmessagecreate">osMessageCreate</a></li>
<li><a href="#osmessageput">osMessagePut</a></li>
<li><a href="#osmessageget">osMessageGet</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#api_2">网络 API</a><ul>
<li><a href="#sal">sal 模组联网接口</a><ul>
<li><a href="#tos_sal_module_register">tos_sal_module_register</a></li>
<li><a href="#tos_sal_module_init">tos_sal_module_init</a></li>
<li><a href="#tos_sal_module_parse_domain">tos_sal_module_parse_domain</a></li>
<li><a href="#tos_sal_module_connect">tos_sal_module_connect</a></li>
<li><a href="#tos_sal_module_send">tos_sal_module_send</a></li>
<li><a href="#tos_sal_module_recv">tos_sal_module_recv</a></li>
<li><a href="#tos_sal_module_recv_timeout">tos_sal_module_recv_timeout</a></li>
<li><a href="#tos_sal_module_sendto">tos_sal_module_sendto</a></li>
<li><a href="#tos_sal_module_recvfrom">tos_sal_module_recvfrom</a></li>
<li><a href="#tos_sal_module_close">tos_sal_module_close</a></li>
</ul>
</li>
<li><a href="#lora">lora 模组联网接口</a><ul>
<li><a href="#tos_lora_module_register">tos_lora_module_register</a></li>
<li><a href="#tos_lora_module_init">tos_lora_module_init</a></li>
<li><a href="#tos_lora_module_join">tos_lora_module_join</a></li>
<li><a href="#tos_lora_module_send">tos_lora_module_send</a></li>
<li><a href="#tos_lora_module_recv">tos_lora_module_recv</a></li>
<li><a href="#tos_lora_module_recv_timeout">tos_lora_module_recv_timeout</a></li>
<li><a href="#tos_lora_module_close">tos_lora_module_close</a></li>
</ul>
</li>
<li><a href="#_7">腾讯定制固件模组联网接口</a><ul>
<li><a href="#tos_tf_module_register">tos_tf_module_register</a></li>
<li><a href="#tos_tf_module_init">tos_tf_module_init</a></li>
<li><a href="#tos_tf_module_info_set">tos_tf_module_info_set</a></li>
<li><a href="#tos_tf_module_mqtt_conn">tos_tf_module_mqtt_conn</a></li>
<li><a href="#tos_tf_module_mqtt_discon">tos_tf_module_mqtt_discon</a></li>
<li><a href="#tos_tf_module_mqtt_pub">tos_tf_module_mqtt_pub</a></li>
<li><a href="#tos_tf_module_mqtt_publ">tos_tf_module_mqtt_publ</a></li>
<li><a href="#tos_tf_module_mqtt_sub">tos_tf_module_mqtt_sub</a></li>
<li><a href="#tos_tf_module_mqtt_unsub">tos_tf_module_mqtt_unsub</a></li>
<li><a href="#tos_tf_module_mqtt_state">tos_tf_module_mqtt_state</a></li>
<li><a href="#tos_tf_module_debug_level_set">tos_tf_module_debug_level_set</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<h1 id="api">内核 API</h1>
<h2 id="_1">系统管理</h2>
<h3 id="tos_knl_init">tos_knl_init</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_knl_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li>功能描述</li>
</ul>
<p>初始化内核。</p>
<ul>
<li>参数解释</li>
</ul>
<p>无</p>
<ul>
<li>返回值</li>
</ul>
<p>K_ERR_NONE 内核初始化成功。</p>
<p>非 K_ERR_NONE 内核初始化失败。</p>
<h3 id="tos_knl_start">tos_knl_start</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_knl_start</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li>功能描述</li>
</ul>
<p>启动内核。</p>
<ul>
<li>参数解释</li>
</ul>
<p>无</p>
<ul>
<li>返回值</li>
</ul>
<p>K_ERR_NONE 内核启动成功。</p>
<p>非 K_ERR_NONE 内核启动失败。</p>
<h3 id="tos_knl_is_running">tos_knl_is_running</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_knl_is_running</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li>功能描述</li>
</ul>
<p>判断内核是否正在运行。</p>
<ul>
<li>参数解释</li>
</ul>
<p>无</p>
<ul>
<li>返回值</li>
</ul>
<p>0 内核不在运行。</p>
<p>非 0 内核正在运行。</p>
<h3 id="tos_knl_irq_enter">tos_knl_irq_enter</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_knl_irq_enter</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li>功能描述</li>
</ul>
<p>此函数应该在中断服务函数开始之前被调用。</p>
<ul>
<li>参数解释</li>
</ul>
<p>无</p>
<ul>
<li>返回值</li>
</ul>
<p>无</p>
<h3 id="tos_knl_irq_leave">tos_knl_irq_leave</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_knl_irq_leave</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li>功能描述</li>
</ul>
<p>此函数应该在中断服务函数结束之前被调用。</p>
<ul>
<li>参数解释</li>
</ul>
<p>无</p>
<ul>
<li>返回值</li>
</ul>
<p>无</p>
<h3 id="tos_knl_sched_lock">tos_knl_sched_lock</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_knl_sched_lock</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li>功能描述</li>
</ul>
<p>锁内核调度。</p>
<ul>
<li>参数解释</li>
</ul>
<p>无</p>
<ul>
<li>返回值</li>
</ul>
<p>K_ERR_NONE 内核调度锁定成功。</p>
<p>K_ERR_KNL_NOT_RUNNING 内核并未处于运行状态。</p>
<p>K_ERR_LOCK_NESTING_OVERFLOW 调度锁溢出。</p>
<p>K_ERR_IN_IRQ 在中断服务程序ISR中上锁</p>
<h3 id="tos_knl_sched_unlock">tos_knl_sched_unlock</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_knl_sched_unlock</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li>功能描述</li>
</ul>
<p>解锁内核调度。</p>
<ul>
<li>参数解释</li>
</ul>
<p>无</p>
<ul>
<li>返回值</li>
</ul>
<p>K_ERR_NONE 内核调度解锁成功。</p>
<p>K_ERR_KNL_NOT_RUNNING 内核并未处于运行状态。</p>
<p>K_ERR_SCHED_NOT_LOCKED 内核调度并未处于锁定状态。</p>
<p>K_ERR_IN_IRQ 在中断服务程序ISR中卸锁</p>
<h2 id="_2">任务管理</h2>
<h3 id="tos_task_create">tos_task_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_create</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">,</span>
<span class="w">                        </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">name</span><span class="p">,</span>
<span class="w">                        </span><span class="n">k_task_entry_t</span><span class="w"> </span><span class="n">entry</span><span class="p">,</span>
<span class="w">                        </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">,</span>
<span class="w">                        </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">,</span>
<span class="w">                        </span><span class="n">k_stack_t</span><span class="w"> </span><span class="o">*</span><span class="n">stk_base</span><span class="p">,</span>
<span class="w">                        </span><span class="kt">size_t</span><span class="w"> </span><span class="n">stk_size</span><span class="p">,</span>
<span class="w">                        </span><span class="n">k_timeslice_t</span><span class="w"> </span><span class="n">timeslice</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th align="left"><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td align="left">task</td>
<td>任务结构体描述符</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">name</td>
<td>任务名称</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">entry</td>
<td>任务入口函数</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">arg</td>
<td>任务入口函数参数</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">prio</td>
<td>任务优先级</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">stk_base</td>
<td>任务栈空间首地址</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">stk_size</td>
<td>任务栈空间的大小</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">timeslice</td>
<td>时间片轮转调度侧策略中，时间片的大小设置，0 表示设置为系统默认值</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 任务创建成功。</p>
<p>K_ERR_TASK_STK_SIZE_INVALID 非法的任务栈大小。</p>
<p>K_ERR_TASK_PRIO_INVALID 非法的任务优先级。</p>
<p>K_ERR_IN_IRQ在中断服务程序lSR中创建任务</p>
<p>K_ERR_OBJ_PTR_NULL传入的指针中包含有NULL指针</p>
<p>K_ERR_TASK_ALREADY_CREATED 该任务已经被创建</p>
<h3 id="tos_task_create_dyn">tos_task_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_create_dyn</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">**</span><span class="n">task</span><span class="p">,</span>
<span class="w">                        </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">name</span><span class="p">,</span>
<span class="w">                        </span><span class="n">k_task_entry_t</span><span class="w"> </span><span class="n">entry</span><span class="p">,</span>
<span class="w">                        </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">,</span>
<span class="w">                        </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">,</span>
<span class="w">                        </span><span class="kt">size_t</span><span class="w"> </span><span class="n">stk_size</span><span class="p">,</span>
<span class="w">                        </span><span class="n">k_timeslice_t</span><span class="w"> </span><span class="n">timeslice</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>动态创建任务，task 句柄及 task 所需的栈皆为系统动态分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th align="left"><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[out]</td>
<td align="left">task</td>
<td>任务结构体描述符</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">name</td>
<td>任务名称</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">entry</td>
<td>任务入口函数</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">arg</td>
<td>任务入口函数参数</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">prio</td>
<td>任务优先级</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">stk_size</td>
<td>任务栈空间的大小</td>
</tr>
<tr>
<td>[in]</td>
<td align="left">timeslice</td>
<td>时间片轮转调度侧策略中，时间片的大小设置，0 表示设置为系统默认值</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 任务创建成功。</p>
<p>K_ERR_TASK_STK_SIZE_INVALID 非法的任务栈大小。</p>
<p>K_ERR_TASK_PRIO_INVALID 非法的任务优先级。</p>
<p>K_ERR_TASK_OUT_OF_MEMORY 系统堆内存不足。</p>
<p>K_ERR_IN_IRQ 在中断服务程序ISR中创建任务</p>
<p>K_ERR_OBJ_PTR_NULL 传入的指针中包含有NULL指针</p>
<p>K_ERR_TASK_ALREADY_CREATED 该任务已经被创建</p>
<h3 id="tos_task_destroy">tos_task_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="n">tos_task_destroy</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">)</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁静态创建的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>task</td>
<td>任务结构体描述符</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 任务销毁成功。</p>
<p>K_ERR_TASK_DESTROY_IDLE 试图销毁 idle 任务（非法）。</p>
<p>K_ERR_IN_IRQ 试图在中断服务程序ISR中销毁任务</p>
<p>K_ERR_OBJ_INVALID 传入的参数不是一个正确的kernel_object</p>
<p>K_ERR_SCHED_LOCKED 已经上锁且删除当前任务(非法 导致死锁)</p>
<p>K_ERR_OBJ_INVALID_ALLOC_TYPE [若开启动态创建]不是一个静态的任务!</p>
<h3 id="tos_task_destroy_dyn">tos_task_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="n">tos_task_destroy_dyn</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">)</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁动态创建（tos_task_create_dyn）的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>task</td>
<td>任务结构体描述符</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 任务销毁成功。</p>
<p>K_ERR_TASK_DESTROY_IDLE 试图销毁 idle 任务（非法）。</p>
<p>K_ERR_OBJ_INVALID 传入的参数不是一个正确的kernel_object</p>
<p>K_ERR_SCHED_LOCKED 已经上锁且删除当前任务(非法 导致死锁)</p>
<p>K_ERR_OBJ_INVALID_ALLOC_TYPE 删除的任务不是一个dynamic创建的task!</p>
<h3 id="tos_task_delay">tos_task_delay</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_delay</span><span class="p">(</span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">delay</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>睡眠当前任务，以系统时钟滴答数为单位。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>delay</td>
<td>任务睡眠时间</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 任务延迟成功。</p>
<p>K_ERR_DELAY_ZERO delay 值为零（非法）。</p>
<p>K_ERR_IN_IRQ 试图在中断服务程序ISR延时</p>
<p>K_ERR_SCHED_LOCKED 已经上锁( 上锁后不能延时当前任务 否则导致无法调度)</p>
<p>K_ERR_DELAY_FOREVER 使用suspend 代替这个forever 的delay</p>
<h3 id="tos_task_delay_abort">tos_task_delay_abort</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_delay_abort</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>取消一个任务的 delay 状态。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>task</td>
<td>任务结构体描述符</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 取消 delay 成功。</p>
<p>K_ERR_TASK_NOT_DELAY task 并未处于 delay 状态。</p>
<p>K_ERR_TASK_SUSPENDED task 被挂起（suspend）。</p>
<p>K_ERR_IN_IRQ 试图在中断服务程序ISR取消延时</p>
<p>K_ERR_OBJ_PTR_NULL 传入的task任务为Null Ptr</p>
<p>K_ERR_OBJ_INVALID 传入的task任务不是一个Kernel对象</p>
<h3 id="tos_task_suspend">tos_task_suspend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_suspend</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>挂起一个任务（剥夺一个任务的运行调度）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>task</td>
<td>任务结构体描述符</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>TOS_ERR_NONE 挂起任务成功。</p>
<p>K_ERR_TASK_SUSPEND_IDLE 试图挂起 idle 任务（非法）。</p>
<p>K_ERR_OBJ_INVALID 传入的task任务不是一个Kernel对象</p>
<p>K_ERR_SCHED_LOCKED 上锁了同时要挂起自己</p>
<h3 id="tos_task_resume">tos_task_resume</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_resume</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>恢复一个任务的调度运行。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>task</td>
<td>任务结构体描述符</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>TOS_ERR_NONE 恢复任务运行成功。</p>
<p>K_ERR_TASK_RESUME_SELF 试图恢复当前任务（非法）。</p>
<p>K_ERR_OBJ_PTR_NULL 传入的task是一个Null ptr</p>
<p>K_ERR_OBJ_INVALID 传入的task不是一个kernel 对象</p>
<h3 id="tos_task_prio_change">tos_task_prio_change</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_prio_change</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">,</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio_new</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>更改一个任务的优先级。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>task</td>
<td>任务结构体描述符</td>
</tr>
<tr>
<td>[in]</td>
<td>prio_new</td>
<td>新的优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 任务优先级更新成功。</p>
<p>K_ERR_TASK_PRIO_INVALID 优先级非法。</p>
<p>K_ERR_OBJ_PTR_NULL 传入的task是一个Null ptr</p>
<p>K_ERR_OBJ_INVALID 传入的task不是一个kernel 对象</p>
<p>K_ERR_IN_IRQ 试图在中断服务程序ISR中改变某个任务的优先级</p>
<h3 id="tos_task_yield">tos_task_yield</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_task_yield</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>当前任务主动放弃 cpu。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>无</p>
<h3 id="tos_task_stack_draught_depth">tos_task_stack_draught_depth</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_task_stack_draught_depth</span><span class="p">(</span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">task</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">depth</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取一个任务栈的最大吃水深度。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>task</td>
<td>任务结构体描述符</td>
</tr>
<tr>
<td>[out]</td>
<td>depth</td>
<td>任务栈的吃水深度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 任务栈状态正常。</p>
<p>K_ERR_TASK_STK_OVERFLOW 任务栈溢出。</p>
<h3 id="tos_task_curr_task_get">tos_task_curr_task_get</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="nf">tos_task_curr_task_get</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取当前正在运行的任务句柄。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_NULL 当前无正在运行任务（内核尚未启动）。</p>
<p>非 K_NULL 任务句柄。</p>
<h3 id="tos_task_walkthru">tos_task_walkthru</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_task_walkthru</span><span class="p">(</span><span class="n">k_task_walker</span><span class="w"> </span><span class="n">walker</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>遍历当前系统已创建的（不包括已删除的）任务，并允许用户传入一个回调，在遍历所有任务时，将任务句柄作为参数调用此回调。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>walker</td>
<td>遍历所有任务时被调用的回调（walker 为一个入参为 k_task_t *的函数）</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>无</p>
<p>非 K_NULL 任务句柄。</p>
<h2 id="_3">堆内存管理</h2>
<h3 id="tos_mmheap_pool_add">tos_mmheap_pool_add</h3>
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mmheap_pool_add</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool_start</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">pool_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向堆内存中添加内存池。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>pool_start</td>
<td>待添加内存池起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>pool_size</td>
<td>待添加内存池大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 添加成功。</p>
<p>K_ERR_MMHEAP_INVALID_POOL_ADDR 内存池起始地址非法。</p>
<p>K_ERR_MMHEAP_INVALID_POOL_SIZE 内存池大小非法。</p>
<h3 id="tos_mmheap_pool_rmv">tos_mmheap_pool_rmv</h3>
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mmheap_pool_rmv</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool_start</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从堆内存中删除内存池。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>pool_start</td>
<td>待删除的内存池起始地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>无</p>
<h3 id="tos_mmheap_alloc">tos_mmheap_alloc</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">tos_mmheap_alloc</span><span class="p">(</span><span class="kt">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从堆内存中分配一块内存。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>size</td>
<td>期望分配的内存大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>分配到的内存起始地址（返回 K_NULL 表示分配失败）。</p>
<h3 id="tos_mmheap_aligned_alloc">tos_mmheap_aligned_alloc</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">tos_mmheap_aligned_alloc</span><span class="p">(</span><span class="kt">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">align</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从堆内存中分配一块内存，此内存起始地址按 align 参数对齐。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>size</td>
<td>期望分配的内存大小</td>
</tr>
<tr>
<td>[in]</td>
<td>align</td>
<td>对齐参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>分配到的内存起始地址（返回 K_NULL 表示分配失败）。</p>
<h3 id="tos_mmheap_realloc">tos_mmheap_realloc</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">tos_mmheap_realloc</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从堆内存中重新分配一块内存。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ptr</td>
<td>原内存起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>size</td>
<td>期望重新分配的内存大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>分配到的内存起始地址（返回 K_NULL 表示分配失败）。</p>
<h3 id="tos_mmheap_free">tos_mmheap_free</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">tos_mmheap_free</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放一片从堆内存中分配到的内存。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ptr</td>
<td>待释放的内存起始地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>无。</p>
<h3 id="tos_mmheap_pool_check">tos_mmheap_pool_check</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mmheap_pool_check</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool_start</span><span class="p">,</span><span class="w"> </span><span class="n">k_mmheap_info_t</span><span class="w"> </span><span class="o">*</span><span class="n">info</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取堆内存中某个池的使用情况。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>pool_start</td>
<td>堆内存中某个池的起始地址</td>
</tr>
<tr>
<td>[out]</td>
<td>info</td>
<td>该池的使用情况（使用量和剩余量信息）</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 函数返回成功。</p>
<p>K_ERR_OBJ_PTR_NULL pool_start 或 info 为空指针。</p>
<h3 id="tos_mmheap_check">tos_mmheap_check</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mmheap_check</span><span class="p">(</span><span class="n">k_mmheap_info_t</span><span class="w"> </span><span class="o">*</span><span class="n">info</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取堆内存的整体使用情况（包含了所有的池的信息）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[out]</td>
<td>info</td>
<td>堆内存的整体使用情况（使用量和剩余量信息）</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 函数返回成功。</p>
<p>K_ERR_OBJ_PTR_NULL info 为空指针。</p>
<h2 id="_4">块内存管理</h2>
<h3 id="tos_mmblk_pool_create">tos_mmblk_pool_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mmblk_pool_create</span><span class="p">(</span><span class="n">k_mmblk_pool_t</span><span class="w"> </span><span class="o">*</span><span class="n">mbp</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool_start</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">blk_num</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">blk_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个块内存池。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mbp</td>
<td>待创建的块内存句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>pool_start</td>
<td>块内存池起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>blk_num</td>
<td>内存块数量</td>
</tr>
<tr>
<td>[in]</td>
<td>blk_size</td>
<td>单个内存块大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 块内存创建成功。</p>
<p>K_ERR_MMBLK_INVALID_POOL_ADDR 块内存池起始地址非法。</p>
<p>K_ERR_MMBLK_INVALID_BLK_SIZE 块内存大小非法。</p>
<h3 id="tos_mmblk_alloc">tos_mmblk_alloc</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mmblk_alloc</span><span class="p">(</span><span class="n">k_mmblk_pool_t</span><span class="w"> </span><span class="o">*</span><span class="n">mbp</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">**</span><span class="n">blk</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从内存池中分配一个内存块。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mbp</td>
<td>块内存句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>blk</td>
<td>返回的块内存起始地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 块内存分配成功，blk 指向分配到的内存块起始地址。</p>
<p>K_ERR_MMBLK_POOL_EMPTY 内存池是空的，blk 为 K_NULL。</p>
<h3 id="tos_mmblk_free">tos_mmblk_free</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mmblk_free</span><span class="p">(</span><span class="n">k_mmblk_pool_t</span><span class="w"> </span><span class="o">*</span><span class="n">mbp</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">blk</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放一个内存块。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th><strong>IN/OUT</strong></th>
<th><strong>参数名</strong></th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mbp</td>
<td>块内存句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>blk</td>
<td>待释放的块内存起始地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 块内存释放成功。</p>
<p>K_ERR_MMBLK_POOL_FULL 内存池是满的。</p>
<h2 id="mutex">互斥量 mutex</h2>
<h3 id="tos_mutex_create">tos_mutex_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mutex_create</span><span class="p">(</span><span class="n">k_mutex_t</span><span class="w"> </span><span class="o">*</span><span class="n">mutex</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个互斥量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex</td>
<td>互斥量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 互斥量创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL mutex 为空指针。</p>
<h3 id="tos_mutex_destroy">tos_mutex_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mutex_destroy</span><span class="p">(</span><span class="n">k_mutex_t</span><span class="w"> </span><span class="o">*</span><span class="n">mutex</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个互斥量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex</td>
<td>互斥量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 互斥量销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL mutex 为空指针。</p>
<p>K_ERR_OBJ_INVALID mutex 指向的不是一个合法的互斥量。</p>
<h3 id="tos_mutex_pend">tos_mutex_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mutex_pend</span><span class="p">(</span><span class="n">k_mutex_t</span><span class="w"> </span><span class="o">*</span><span class="n">mutex</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试获取一个互斥量（永久阻塞式等待）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex</td>
<td>互斥量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 获取互斥量成功。</p>
<p>K_ERR_MUTEX_NESTING_OVERFLOW 互斥量拥有者嵌套获取溢出。</p>
<p>K_ERR_MUTEX_NESTING 互斥量拥有者嵌套获取。</p>
<p>K_ERR_PEND_SCHED_LOCKED 此互斥量被其他任务持有，且系统调度处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 当前任务试图获取的互斥量被销毁（tos_mutex_destroy）了。</p>
<h3 id="tos_mutex_pend_timed">tos_mutex_pend_timed</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mutex_pend</span><span class="p">(</span><span class="n">k_mutex_t</span><span class="w"> </span><span class="o">*</span><span class="n">mutex</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试获取一个互斥量（有限时间内的阻塞等待）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex</td>
<td>互斥量句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 获取互斥量成功。</p>
<p>K_ERR_MUTEX_NESTING_OVERFLOW 互斥量拥有者嵌套获取溢出。</p>
<p>K_ERR_MUTEX_NESTING 互斥量拥有者嵌套获取。</p>
<p>K_ERR_PEND_NOWAIT 此互斥量被其他任务持有，同时 timeout 参数为 TOS_TIME_NOWAIT（表示获取不到互斥量时立即返回）</p>
<p>K_ERR_PEND_SCHED_LOCKED 此互斥量被其他任务持有（获取失败），且系统调度处于锁定状态。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 时间范围内未获取到互斥量。</p>
<p>K_ERR_PEND_DESTROY 当前任务试图获取的互斥量被销毁（tos_mutex_destroy）了。</p>
<h3 id="tos_mutex_post">tos_mutex_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mutex_post</span><span class="p">(</span><span class="n">k_mutex_t</span><span class="w"> </span><span class="o">*</span><span class="n">mutex</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放互斥量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex</td>
<td>互斥量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 互斥量释放成功。</p>
<p>K_ERR_MUTEX_NOT_OWNER 当前任务并非此互斥量的拥有者。</p>
<p>K_ERR_MUTEX_NESTING_OVERFLOW 互斥量拥有者嵌套释放溢出。</p>
<p>K_ERR_MUTEX_NESTING 互斥量拥有者嵌套释放。</p>
<h2 id="semaphore">信号量 semaphore</h2>
<h3 id="tos_sem_create">tos_sem_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sem_create</span><span class="p">(</span><span class="n">k_sem_t</span><span class="w"> </span><span class="o">*</span><span class="n">sem</span><span class="p">,</span><span class="w"> </span><span class="n">k_sem_cnt_t</span><span class="w"> </span><span class="n">init_count</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个信号量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sem</td>
<td>信号量句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>init_count</td>
<td>信号量初始量</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 信号量创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL sem 指针为空。</p>
<h3 id="tos_sem_create_max">tos_sem_create_max</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sem_create_max</span><span class="p">(</span><span class="n">k_sem_t</span><span class="w"> </span><span class="o">*</span><span class="n">sem</span><span class="p">,</span><span class="w"> </span><span class="n">k_sem_cnt_t</span><span class="w"> </span><span class="n">init_count</span><span class="p">,</span><span class="w"> </span><span class="n">k_sem_cnt_t</span><span class="w"> </span><span class="n">max_count</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个信号量并指定信号量的最大值。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sem</td>
<td>信号量句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>init_count</td>
<td>信号量初始量</td>
</tr>
<tr>
<td>[in]</td>
<td>max_count</td>
<td>信号量的最大值</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 信号量创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL sem 指针为空。</p>
<h3 id="tos_sem_destroy">tos_sem_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sem_destroy</span><span class="p">(</span><span class="n">k_sem_t</span><span class="w"> </span><span class="o">*</span><span class="n">sem</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个信号量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sem</td>
<td>信号量数据结构指针</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 信号量销毁成功。</p>
<p>K_ERR_OBJ_INVALID sem 指向的不是一个合法的信号量。</p>
<p>K_ERR_OBJ_PTR_NULL sem 指针为空。</p>
<h3 id="tos_sem_pend">tos_sem_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sem_pend</span><span class="p">(</span><span class="n">k_sem_t</span><span class="w"> </span><span class="o">*</span><span class="n">sem</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试获取一个信号量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sem</td>
<td>信号量句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 获取信号量成功。</p>
<p>K_ERR_PEND_NOWAIT 获取信号量失败（信号量资源不足），同时 timeout 参数为 TOS_TIME_NOWAIT（表示获取不到信号量时立即返回）</p>
<p>K_ERR_PEND_SCHED_LOCKED 获取信号量失败，同时系统调度处于锁定状态。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 超时范围内未获取到信号量。</p>
<p>K_ERR_PEND_DESTROY 试图获取的信号量被销毁了（tos_sem_destroy）</p>
<h3 id="tos_sem_post">tos_sem_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sem_post</span><span class="p">(</span><span class="n">k_sem_t</span><span class="w"> </span><span class="o">*</span><span class="n">sem</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放信号量，并唤醒等待队列上的一个任务。如果有多个任务在此信号量的等待队列上，唤醒优先级最高的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sem</td>
<td>信号量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 信号量释放成功。</p>
<p>K_ERR_SEM_OVERFLOW 信号量值溢出。</p>
<h3 id="tos_sem_post_all">tos_sem_post_all</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sem_post_all</span><span class="p">(</span><span class="n">k_sem_t</span><span class="w"> </span><span class="o">*</span><span class="n">sem</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放信号量，并唤醒等待队列上的所有任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sem</td>
<td>信号量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 信号量释放成功。</p>
<p>K_ERR_SEM_OVERFLOW 信号量值溢出。</p>
<h2 id="event">事件 event</h2>
<h3 id="tos_event_create">tos_event_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_event_create</span><span class="p">(</span><span class="n">k_event_t</span><span class="w"> </span><span class="o">*</span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="n">k_event_flag_t</span><span class="w"> </span><span class="n">init_flag</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个事件。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>event</td>
<td>事件句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>init_flag</td>
<td>事件初始旗标</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 事件创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL event 指针为空。</p>
<h3 id="tos_event_destroy">tos_event_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_event_destroy</span><span class="p">(</span><span class="n">k_event_t</span><span class="w"> </span><span class="o">*</span><span class="n">event</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个事件。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>event</td>
<td>事件句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 事件销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL event 指针为空。</p>
<p>K_ERR_OBJ_INVALID event 指向的不是一个合法的事件。</p>
<h3 id="tos_event_pend">tos_event_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_event_pend</span><span class="p">(</span><span class="n">k_event_t</span><span class="w"> </span><span class="o">*</span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="n">k_event_flag_t</span><span class="w"> </span><span class="n">flag_expect</span><span class="p">,</span><span class="w"> </span><span class="n">k_event_flag_t</span><span class="w"> </span><span class="o">*</span><span class="n">flag_match</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">,</span><span class="w"> </span><span class="n">k_opt_t</span><span class="w"> </span><span class="n">opt</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试获取一个特定的事件。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>event</td>
<td>事件句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>flag_expect</td>
<td>期望获取到的事件旗标</td>
</tr>
<tr>
<td>[out]</td>
<td>flag_match</td>
<td>实际获取到的事件旗标</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
<tr>
<td>[in]</td>
<td>opt</td>
<td>选项</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>注意</strong></li>
</ul>
<p>opt 选项说明：</p>
<p>1、TOS_OPT_EVENT_PEND_ANY</p>
<p>尝试从事件中获取一组旗标，并且这一组旗标包含 flag_expect 中标识的任意一个旗标，如果在此场景下视作 event 获取成功，则 opt 传递此参数。</p>
<p>举例来说，如果传入的 flag_expect 为 0x9（0x8 | 0x1），且 opt 为 TOS_OPT_EVENT_PEND_ANY，则 event 包含的旗标包含 0x8 或者 0x1 即视为事件获取成功，也就是说，event 包含的旗标为 (0x8 | X, X 为整数，且 X∈(0, 0xFFFFFFFF])，或者 (0x1 | X, X 为整数，且 X∈(0, 0xFFFFFFFF])。</p>
<p>2、TOS_OPT_EVENT_PEND_ALL</p>
<p>尝试从事件中获取一组旗标，并且这一组旗标必须至少包含 flag_expect 中标识的所有旗标，如果只在此种场景下视作 event 获取成功，则 opt 传递此参数。</p>
<p>举例来说，如果传入的 flag_expect 为 0x9（0x8 | 0x1），且 opt 为 TOS_OPT_EVENT_PEND_ALL，则 event 包含的旗标至少为 0x9 的最小全集才视为事件获取成功，也就是说，event 包含的旗标应为 (0x9 | X, X 为整数，且 X∈(0, 0xFFFFFFFF])。</p>
<p>3、TOS_OPT_EVENT_PEND_CLR</p>
<p>如果希望读取完事件后，直接复位清空 event 的所有旗标，则 opt 传递此参数。</p>
<p>举例来说，原 event 包含旗标为 0x9，在传递 TOS_OPT_EVENT_PEND_CLR 参数并成功获取 event 中的旗标后，event 包含的旗标会复位为 0x0。</p>
<p>如果希望一次传入多个选项，可以用逻辑“或”将多个参数连接传入，譬如同时希望采用 TOS_OPT_EVENT_PEND_ANY 语义及 TOS_OPT_EVENT_PEND_CLR，可以传入（TOS_OPT_EVENT_PEND_ANY | TOS_OPT_EVENT_PEND_CLR）。</p>
<p>需要注意的是，不可以同时传入 TOS_OPT_EVENT_PEND_ANY 与 TOS_OPT_EVENT_PEND_ALL。</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 读取特定的事件成功。</p>
<p>K_ERR_EVENT_PEND_OPT_INVALID opt 参数非法。</p>
<p>K_ERR_PEND_NOWAIT 未能从 event 中获取到期望的旗标，并且 timeout 参数为 TOS_TIME_NOWAIT（表示未获取到期望旗标时立即返回）。</p>
<p>K_ERR_PEND_SCHED_LOCKED 未能从 event 中获取到期望的旗标，并且系统调度处于锁定的状态。</p>
<p>K_ERR_PEND_TIMEOUT 在超时范围内未能从 event 中获取到期望的旗标。</p>
<p>K_ERR_PEND_DESTROY 尝试获取旗标的事件被销毁了（tos_event_destroy）。</p>
<h3 id="tos_event_post">tos_event_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_event_post</span><span class="p">(</span><span class="n">k_event_t</span><span class="w"> </span><span class="o">*</span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="n">k_event_flag_t</span><span class="w"> </span><span class="n">flag</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向事件中放置一组旗标</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>event</td>
<td>事件句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>flag</td>
<td>要放置的旗标</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>注意</strong></li>
</ul>
<p>调用此接口放置一组旗标时，原 event 中包含的旗标将被覆盖。</p>
<p>举例来说，如果原事件的旗标为 0x1，并且要放置的旗标为 0x8，此接口调用结束后，事件的旗标将被覆写为 0x8。</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 旗标放置成功。</p>
<p>K_ERR_OBJ_PTR_NULL event 为空指针。</p>
<p>K_ERR_OBJ_INVALID event 指向的并不是一个合法的事件。</p>
<h3 id="tos_event_post_keep">tos_event_post_keep</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_event_post_keep</span><span class="p">(</span><span class="n">k_event_t</span><span class="w"> </span><span class="o">*</span><span class="n">event</span><span class="p">,</span><span class="w"> </span><span class="n">k_event_flag_t</span><span class="w"> </span><span class="n">flag</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向事件中放置一组旗标，原 event 中包含的旗标将被保留。</p>
<p>举例来说，如果原事件的旗标为 0x1，并且要放置的旗标为 0x8，此接口调用结束后，事件的旗标将被修改为 0x9(0x8 | 0x1)，也就是说，原事件的包含的旗标被保留。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>event</td>
<td>事件句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>flag</td>
<td>要放置的旗标</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 旗标放置成功。</p>
<p>K_ERR_OBJ_PTR_NULL event 为空指针。</p>
<p>K_ERR_OBJ_INVALID event 指向的并不是一个合法的事件。</p>
<h2 id="completion">完成量 completion</h2>
<h3 id="tos_completion_create">tos_completion_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_create</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个完成量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 完成量创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL completion 指针为空。</p>
<h3 id="tos_completion_destroy">tos_completion_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_destroy</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个完成量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 完成量销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL completion 指针为空。</p>
<p>K_ERR_OBJ_INVALID completion 指向的不是一个合法的完成量。</p>
<h3 id="tos_completion_pend">tos_completion_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_pend</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>等待完成量完成（永久阻塞等待）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 完成量已完成。</p>
<p>K_ERR_PEND_SCHED_LOCKED 完成量没有完成，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的完成量被删除了。</p>
<h3 id="tos_completion_pend_timed">tos_completion_pend_timed</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_pend_timed</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试等待完成量完成（有限时间内的阻塞等待）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 完成量已完成。</p>
<p>K_ERR_PEND_NOWAIT 此完成量尚未完成，同时 timeout 参数为 TOS_TIME_NOWAIT（表示完成量未完成时立即返回）</p>
<p>K_ERR_PEND_SCHED_LOCKED 完成量没有完成，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的完成量被删除了。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 时间范围内完成量未完成。</p>
<h3 id="tos_completion_post">tos_completion_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_post</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放完成量（此完成量状态变为已完成），并唤醒等待队列上的一个任务。如果有多个任务在此完成量的等待队列上，唤醒优先级最高的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 完成量释放成功。</p>
<h3 id="tos_completion_post_all">tos_completion_post_all</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_post_all</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放完成量（此完成量状态变为已完成），并唤醒等待队列上的所有任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 完成量释放成功。</p>
<h3 id="tos_completion_reset">tos_completion_reset</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_reset</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>复位完成量（将此完成量状态更改为未完成）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 完成量复位成功。</p>
<h3 id="tos_completion_is_done">tos_completion_is_done</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_completion_is_done</span><span class="p">(</span><span class="n">k_completion_t</span><span class="w"> </span><span class="o">*</span><span class="n">completion</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断此完成量是否已完成。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>completion</td>
<td>完成量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 完成量已完成。</p>
<p>K_FALSE 完成量未完成。</p>
<h2 id="countdown-latch">计数锁 countdown latch</h2>
<h3 id="tos_countdownlatch_create">tos_countdownlatch_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_countdownlatch_create</span><span class="p">(</span><span class="n">k_countdownlatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">countdownlatch</span><span class="p">,</span><span class="w"> </span><span class="n">k_countdownlatch_cnt_t</span><span class="w"> </span><span class="n">count</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个计数锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>countdownlatch</td>
<td>计数锁句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>count</td>
<td>期望等待的计数值</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计数锁创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL countdownlatch 指针为空。</p>
<h3 id="tos_countdownlatch_destroy">tos_countdownlatch_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_countdownlatch_destroy</span><span class="p">(</span><span class="n">k_countdownlatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">countdownlatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个计数锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>countdownlatch</td>
<td>计数锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计数锁销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL countdownlatch 指针为空。</p>
<p>K_ERR_OBJ_INVALID countdownlatch 指向的不是一个合法的计数锁。</p>
<h3 id="tos_countdownlatch_pend">tos_countdownlatch_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_countdownlatch_pend</span><span class="p">(</span><span class="n">k_countdownlatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">countdownlatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>等待计数锁完成（永久阻塞等待）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>countdownlatch</td>
<td>计数量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计数锁已完成。</p>
<p>K_ERR_PEND_SCHED_LOCKED 计数锁没有完成，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的计数锁被删除了。</p>
<h3 id="tos_countdownlatch_pend_timed">tos_countdownlatch_pend_timed</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_countdownlatch_pend_timed</span><span class="p">(</span><span class="n">k_countdownlatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">countdownlatch</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试等待计数锁完成（有限时间内的阻塞等待）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>countdownlatch</td>
<td>计数锁句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计数锁已完成。</p>
<p>K_ERR_PEND_NOWAIT 此计数锁尚未完成，同时 timeout 参数为 TOS_TIME_NOWAIT（表示计数锁未完成时立即返回）</p>
<p>K_ERR_PEND_SCHED_LOCKED 计数锁没有完成，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的计数锁被删除了。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 时间范围内计数锁未完成。</p>
<h3 id="tos_countdownlatch_post">tos_countdownlatch_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_countdownlatch_post</span><span class="p">(</span><span class="n">k_countdownlatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">countdownlatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>计数锁（此计数锁的计数值减一），并唤醒等待队列上的一个任务。如果有多个任务在此计数锁的等待队列上，唤醒优先级最高的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>countdownlatch</td>
<td>计数锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计数锁释放成功。</p>
<h3 id="tos_countdownlatch_reset">tos_countdownlatch_reset</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_countdownlatch_reset</span><span class="p">(</span><span class="n">k_countdownlatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">countdownlatch</span><span class="p">,</span><span class="w"> </span><span class="n">k_countdownlatch_cnt_t</span><span class="w"> </span><span class="n">count</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>复位计数锁（将此计数锁的计数值复位为新的期望值）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>countdownlatch</td>
<td>计数锁句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>count</td>
<td>期望复位的新的计数值</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计数锁复位成功。</p>
<h2 id="barrier">栅栏 barrier</h2>
<h3 id="tos_barrier_create">tos_barrier_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_barrier_create</span><span class="p">(</span><span class="n">k_barrier_t</span><span class="w"> </span><span class="o">*</span><span class="n">barrier</span><span class="p">,</span><span class="w"> </span><span class="n">k_barrier_cnt_t</span><span class="w"> </span><span class="n">count</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个栅栏。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>barrier</td>
<td>栅栏句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>count</td>
<td>期望等待的计数值</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 栅栏创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL barrier 指针为空。</p>
<h3 id="tos_barrier_destroy">tos_barrier_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_barrier_destroy</span><span class="p">(</span><span class="n">k_barrier_t</span><span class="w"> </span><span class="o">*</span><span class="n">barrier</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个栅栏。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>barrier</td>
<td>栅栏句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 栅栏销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL barrier 指针为空。</p>
<p>K_ERR_OBJ_INVALID barrier 指向的不是一个合法的栅栏。</p>
<h3 id="tos_barrier_pend">tos_barrier_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_barrier_pend</span><span class="p">(</span><span class="n">k_barrier_t</span><span class="w"> </span><span class="o">*</span><span class="n">barrier</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>等待栅栏全部解除（永久阻塞等待）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>barrier</td>
<td>栅栏句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 栅栏已完成。</p>
<p>K_ERR_PEND_SCHED_LOCKED 栅栏没有完成，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的栅栏被删除了。</p>
<p>K_ERR_BARRIER_OVERFLOW 栅栏的 pend 次数超过了初始的 count 数量。</p>
<h3 id="tos_barrier_reset">tos_barrier_reset</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_barrier_reset</span><span class="p">(</span><span class="n">k_barrier_t</span><span class="w"> </span><span class="o">*</span><span class="n">barrier</span><span class="p">,</span><span class="w"> </span><span class="n">k_barrier_cnt_t</span><span class="w"> </span><span class="n">count</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>复位栅栏（将栅栏的 count 计数复位）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>barrier</td>
<td>栅栏句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>count</td>
<td>复位的计数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 栅栏复位成功。</p>
<p>K_ERR_OBJ_PTR_NULL barrier 指针为空。</p>
<p>K_ERR_OBJ_INVALID barrier 指向的不是一个合法的栅栏。</p>
<h2 id="rwlock">读写锁 rwlock</h2>
<h3 id="tos_rwlock_create">tos_rwlock_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_create</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个读写锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 读写锁创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL rwlock 指针为空。</p>
<h3 id="tos_rwlock_destroy">tos_rwlock_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_destroy</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个栅栏。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 读写锁销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL rwlock 指针为空。</p>
<p>K_ERR_OBJ_INVALID rwlock 指向的不是一个合法的读写锁。</p>
<h3 id="tos_rwlock_rpend_timed">tos_rwlock_rpend_timed</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_rpend_timed</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>有限的时间内尝试获取读锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>超时时限</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功获取读锁。</p>
<p>K_ERR_PEND_SCHED_LOCKED 未成功获取到读锁，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的读锁被删除了。</p>
<p>K_ERR_PEND_TIMEOUT 未在超时时限内成功获取到读锁。</p>
<p>K_ERR_RWLOCK_READERS_TO_MANY 已获取读锁的读者过多。</p>
<h3 id="tos_rwlock_rpend">tos_rwlock_rpend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_rpend</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>永久性阻塞尝试获取读锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功获取读锁。</p>
<p>K_ERR_PEND_SCHED_LOCKED 在超时时限内未成功获取到读锁，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的读锁被删除了。</p>
<p>K_ERR_RWLOCK_READERS_TO_MANY 已获取读锁的读者过多。</p>
<h3 id="tos_rwlock_rpend_try">tos_rwlock_rpend_try</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_rpend_try</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试获取读锁，且并不阻塞等待，立即返回错误码。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功获取读锁。</p>
<p>K_ERR_PEND_SCHED_LOCKED 在超时时限内未成功获取到读锁，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的读锁被删除了。</p>
<p>K_ERR_RWLOCK_READERS_TO_MANY 已获取读锁的读者过多。</p>
<h3 id="tos_rwlock_wpend_timed">tos_rwlock_wpend_timed</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_wpend_timed</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>有限的时间内尝试获取写锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>超时时限</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功获取读锁。</p>
<p>K_ERR_PEND_SCHED_LOCKED 未成功获取到写锁，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的写锁被删除了。</p>
<p>K_ERR_PEND_TIMEOUT 未在超时时限内成功获取到写锁。</p>
<p>K_ERR_RWLOCK_WAITING_WRITERS_TO_MANY 尝试获取写锁的任务过多。</p>
<h3 id="tos_rwlock_wpend">tos_rwlock_wpend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_wpend</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>永久性阻塞尝试获取写锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功获取写锁。</p>
<p>K_ERR_PEND_SCHED_LOCKED 在超时时限内未成功获取到写锁，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的写锁被删除了。</p>
<p>K_ERR_RWLOCK_WAITING_WRITERS_TO_MANY 尝试获取写锁的任务过多。</p>
<h3 id="tos_rwlock_wpend_try">tos_rwlock_wpend_try</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_wpend_try</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试获取写锁，且并不阻塞等待，立即返回错误码。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功获取写锁。</p>
<p>K_ERR_PEND_SCHED_LOCKED 在超时时限内未成功获取到写锁，并且系统调度锁处于锁定状态。</p>
<p>K_ERR_PEND_DESTROY 尝试等待的写锁被删除了。</p>
<p>K_ERR_RWLOCK_WAITING_WRITERS_TO_MANY 尝试获取写锁的任务过多。</p>
<h3 id="tos_rwlock_rpost">tos_rwlock_rpost</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_rpost</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放一个读锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功释放读锁。</p>
<p>K_ERR_RWLOCK_NOT_READING 当前任务并非此读锁拥有者。</p>
<h3 id="tos_rwlock_wpost">tos_rwlock_wpost</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_wpost</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放一个写锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功释放写锁。</p>
<p>K_ERR_RWLOCK_NOT_WRITTING 当前任务并非此写锁拥有者。</p>
<h3 id="tos_rwlock_post">tos_rwlock_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_rwlock_post</span><span class="p">(</span><span class="n">k_rwlock_t</span><span class="w"> </span><span class="o">*</span><span class="n">rwlock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放一个读写锁。</p>
<p>如果当前读写锁被读者持有，则释放读锁；如果是被写者持有，则释放写锁。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>rwlock</td>
<td>读写锁句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 成功释放写锁。</p>
<p>K_ERR_RWLOCK_NOT_TAKEN 此读写锁并未被任何读者或写者占有。</p>
<h2 id="message-queue">消息队列 message queue</h2>
<h3 id="tos_msg_q_create">tos_msg_q_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_create</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">msg_cnt</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个消息队列（消息就是指针）。消息队列是用来在任务间传递指针信息的机制。pool 由用户传入，pool 是一片大小为 (msg*cnt * sizeof(void _)) 的内存 buffer。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>pool</td>
<td>消息队列的 buffer 池</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_cnt</td>
<td>消息队列的最大消息数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 消息队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL msg_q 指针为空。</p>
<h3 id="tos_msg_q_create_dyn">tos_msg_q_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_create_dyn</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">msg_cnt</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>动态创建一个消息队列（消息就是指针）。消息队列是用来在任务间传递指针信息的机制。内部 buffer 由动态内存分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_cnt</td>
<td>消息队列的最大消息数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 消息队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL msg_q 指针为空。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_msg_q_destroy">tos_msg_q_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_destroy</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个消息队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 消息队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL msg_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID msg_q 指向的不是一个合法的消息队列。</p>
<h3 id="tos_msg_q_destroy_dyn">tos_msg_q_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_destroy_dyn</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建的（tos_msg_q_create_dyn）消息队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 消息队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL msg_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID msg_q 指向的不是一个合法的消息队列。</p>
<h3 id="tos_msg_q_flush">tos_msg_q_flush</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_flush</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗消息队列（丢弃消息队列中的所有消息）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 消息队列冲洗成功。</p>
<p>K_ERR_OBJ_PTR_NULL msg_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID msg_q 指向的不是一个合法的消息队列。</p>
<h3 id="tos_msg_q_pend">tos_msg_q_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_pend</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">**</span><span class="n">msg_ptr</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试从消息队列中获取消息。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>msg_ptr</td>
<td>获取到的消息地址</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 从消息队列获取消息成功，msg_addr 和 msg_size 分别是获取到的消息地址和消息长度。</p>
<p>K_ERR_PEND_NOWAIT 未能从消息队列中获取到消息，并且 timeout 参数为 TOS_TIME_NOWAIT（表示获取不到消息时立即返回）。</p>
<p>K_ERR_PEND_SCHED_LOCKED 未能从消息队列中获取到消息，并且系统调度处于锁定状态。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 超时范围内未能从消息队列中获取到消息。</p>
<p>K_ERR_PEND_DESTROY 尝试获取消息的队列被销毁了（tos_msg_q_destroy）。</p>
<h3 id="tos_msg_q_post">tos_msg_q_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_post</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">msg_ptr</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向消息队列中放入一个消息，并唤醒等待队列上的一个任务。如果有多个任务在此消息队列的等待队列上，唤醒优先级最高的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_ptr</td>
<td>消息地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向消息队列中放入消息成功。</p>
<p>K_ERR_RING_Q_FULL 消息队列已满。</p>
<h3 id="tos_msg_q_post_all">tos_msg_q_post_all</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_msg_q_post_all</span><span class="p">(</span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">msg_ptr</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向消息队列中放入一个消息，并唤醒等待队列上的所有任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>msg_q</td>
<td>消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_ptr</td>
<td>消息地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向消息队列中放入消息成功。</p>
<p>K_ERR_RING_Q_FULL 消息队列已满。</p>
<h2 id="mail-queue">邮箱队列 mail queue</h2>
<h3 id="tos_mail_q_create">tos_mail_q_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_create</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个邮箱队列（邮件是一片固定大小的内存）。邮箱队列是用来在任务间传递具有特定大小的内存信息的机制。pool 由用户传入，pool 是一片大小为 (mail_cnt* mail_size) 的内存 buffer。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>pool</td>
<td>邮箱队列的 buffer 池</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_cnt</td>
<td>邮件的最大数量</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 邮箱队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL mail_q 指针为空。</p>
<h3 id="tos_mail_q_create_dyn">tos_mail_q_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_create_dyn</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>动态创建一个邮箱队列（邮件是一片固定大小的内存）。邮箱队列是用来在任务间传递具有特定大小的内存信息的机制。内部 buffer 由动态内存分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_cnt</td>
<td>邮件的最大数量</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 邮箱队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL mail_q 指针为空。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_mail_q_destroy">tos_mail_q_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_destroy</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个邮箱队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 邮箱队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL mail_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID mail_q 指向的不是一个合法的邮箱队列。</p>
<h3 id="tos_mail_q_destroy_dyn">tos_mail_q_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_destroy_dyn</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建的（tos_mail_q_create_dyn）邮箱队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 邮箱队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL mail_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID mail_q 指向的不是一个合法的邮箱队列。</p>
<h3 id="tos_mail_q_flush">tos_mail_q_flush</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_flush</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗邮箱队列（丢弃邮箱队列中的所有邮件）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 邮箱队列冲洗成功。</p>
<p>K_ERR_OBJ_PTR_NULL mail_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID mail_q 指向的不是一个合法的邮箱队列。</p>
<h3 id="tos_mail_q_pend">tos_mail_q_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_pend</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">mail_buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试从邮箱队列中获取邮件。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>mail_buf</td>
<td>用来承载邮件内容的 buffer 地址</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>获取到的邮件长度</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 从邮箱队列获取邮件成功，mail_buf 中被写入邮件内容，msg_size 获取到的邮件长度。</p>
<p>K_ERR_PEND_NOWAIT 未能从邮箱队列中获取到邮件，并且 timeout 参数为 TOS_TIME_NOWAIT（表示获取不到邮件时立即返回）。</p>
<p>K_ERR_PEND_SCHED_LOCKED 未能从邮箱队列中获取到邮件，并且系统调度处于锁定状态。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 超时范围内未能从邮箱队列中获取到邮件。</p>
<p>K_ERR_PEND_DESTROY 尝试获取邮件的队列被销毁了（tos_mail_q_destroy）。</p>
<h3 id="tos_mail_q_post">tos_mail_q_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_post</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">mail_buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向邮箱队列中放入一个邮件，并唤醒等待队列上的一个任务。如果有多个任务在此邮箱队列的等待队列上，唤醒优先级最高的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_buf</td>
<td>要放入邮箱队列的邮件</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向邮箱队列中放入邮件成功。</p>
<p>K_ERR_RING_Q_FULL 邮箱队列已满。</p>
<h3 id="tos_mail_q_post_all">tos_mail_q_post_all</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_mail_q_post_all</span><span class="p">(</span><span class="n">k_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">mail_buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向邮箱队列中放入一个邮件，并唤醒等待队列上的所有任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mail_q</td>
<td>邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_buf</td>
<td>要放入邮箱队列的邮件</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向邮箱队列中放入邮件成功。</p>
<p>K_ERR_RING_Q_FULL 邮箱队列已满。</p>
<h2 id="priority-message-queue">优先级消息队列 priority message queue</h2>
<h3 id="tos_prio_msg_q_create">tos_prio_msg_q_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_create</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">msg_cnt</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个优先级消息队列（消息就是指针）。优先级消息队列是用来在任务间传递指针信息的机制，与消息队列不同的地方在于，优先级消息队列可以给消息赋予一个优先级，较高优先级（数值上更小）的消息会比较低优先级的消息更快传递到等待任务。pool 由用户传入，pool 是一片大小为 (msg*cnt * sizeof(void _)) 的内存 buffer。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>pool</td>
<td>优先级消息队列的 buffer 池</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_cnt</td>
<td>优先级消息队列的最大消息数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级消息队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_msg_q 指针为空。</p>
<h3 id="tos_prio_msg_q_create_dyn">tos_prio_msg_q_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_create_dyn</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">msg_cnt</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>动态创建一个优先级消息队列（消息就是指针）。优先级消息队列是用来在任务间传递指针信息的机制，与消息队列不同的地方在于，优先级队列可以给消息赋予一个优先级，较高优先级（数值上更小）的消息会比较低优先级的消息更快传递到等待任务。内部 buffer 由动态内存分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_cnt</td>
<td>优先级消息队列的最大消息数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级消息队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_msg_q 指针为空。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_prio_msg_q_destroy">tos_prio_msg_q_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_destroy</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个优先级消息队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级消息队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级消息队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL msg_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID prio_msg_q 指向的不是一个合法的优先级消息队列。</p>
<h3 id="tos_prio_msg_q_destroy_dyn">tos_prio_msg_q_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_destroy_dyn</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建的（tos_prio_msg_q_create_dyn）优先级消息队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级息队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级消息队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_msg_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID prio_msg_q 指向的不是一个合法的优先级消息队列。</p>
<h3 id="tos_prio_msg_q_flush">tos_prio_msg_q_flush</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_flush</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗 优先级消息队列（丢弃优先级消息队列中的所有消息）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级息队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级消息队列冲洗成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_msg_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID prio_msg_q 指向的不是一个合法的优先级消息队列。</p>
<h3 id="tos_prio_msg_q_pend">tos_prio_msg_q_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_pend</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">**</span><span class="n">msg_ptr</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试从消息队列中获取消息。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级消息队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>msg_ptr</td>
<td>获取到的消息地址</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 从优先级消息队列获取消息成功，msg_addr 和 msg_size 分别是获取到的消息地址和消息长度。</p>
<p>K_ERR_PEND_NOWAIT 未能从优先级消息队列中获取到消息，并且 timeout 参数为 TOS_TIME_NOWAIT（表示获取不到消息时立即返回）。</p>
<p>K_ERR_PEND_SCHED_LOCKED 未能从优先级消息队列中获取到消息，并且系统调度处于锁定状态。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 超时范围内未能从优先级消息队列中获取到消息。</p>
<p>K_ERR_PEND_DESTROY 尝试获取消息的队列被销毁了（tos_prio_msg_q_destroy）。</p>
<h3 id="tos_prio_msg_q_post">tos_prio_msg_q_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_post</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">msg_ptr</span><span class="p">,</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向优先级消息队列中放入一个消息，并唤醒等待队列上的一个任务。如果有多个任务在此优先级消息队列的等待队列上，唤醒优先级最高的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_ptr</td>
<td>消息地址</td>
</tr>
<tr>
<td>[in]</td>
<td>prio</td>
<td>消息的优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向优先级消息队列中放入消息成功。</p>
<p>K_ERR_RING_Q_FULL 优先级消息队列已满。</p>
<h3 id="tos_prio_msg_q_post_all">tos_prio_msg_q_post_all</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_post_all</span><span class="p">(</span><span class="n">k_prio_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_msg_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">msg_ptr</span><span class="p">,</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向优先级消息队列中放入一个消息，并唤醒等待队列上的所有任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_msg_q</td>
<td>优先级消息队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>msg_ptr</td>
<td>消息地址</td>
</tr>
<tr>
<td>[in]</td>
<td>prio</td>
<td>消息的优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向优先级消息队列中放入消息成功。</p>
<p>K_ERR_RING_Q_FULL 优先级消息队列已满。</p>
<h2 id="priority-mail-queue">优先级邮箱队列 priority mail queue</h2>
<h3 id="tos_prio_mail_q_create">tos_prio_mail_q_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_msg_q_create</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个优先级邮箱队列（邮件是一片固定大小的内存）。优先级邮箱队列是用来在任务间传递具有特定大小的内存信息的机制，与邮箱队列不同的地方在于，优先级邮箱队列可以给邮件赋予一个优先级，较高优先级（数值上更小）的邮件会比较低优先级的邮件更快传递到等待任务。pool 由用户传入，pool 是一片大小为 (mail_cnt* mail_size) 的内存 buffer。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>pool</td>
<td>优先级邮箱队列的 buffer 池</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_cnt</td>
<td>邮件的最大数量</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级邮箱队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_mail_q 指针为空。</p>
<h3 id="tos_prio_mail_q_create_dyn">tos_prio_mail_q_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_mail_q_create_dyn</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>动态创建一个优先级邮箱队列（邮件是一片固定大小的内存）。优先级邮箱队列是用来在任务间传递具有特定大小的内存信息的机制。内部 buffer 由动态内存分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_cnt</td>
<td>邮件的最大数量</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级邮箱队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_mail_q 指针为空。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_prio_mail_q_destroy">tos_prio_mail_q_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_mail_q_destroy</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个邮箱队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级邮箱队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_mail_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID prio_mail_q 指向的不是一个合法的邮箱队列。</p>
<h3 id="tos_prio_mail_q_destroy_dyn">tos_prio_mail_q_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_mail_q_destroy_dyn</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建的（tos_mail_q_create_dyn）优先级邮箱队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级邮箱队列销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_mail_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID prio_mail_q 指向的不是一个合法的优先级邮箱队列。</p>
<h3 id="tos_prio_mail_q_flush">tos_prio_mail_q_flush</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_mail_q_flush</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗邮箱队列（丢弃邮箱队列中的所有邮件）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级邮箱队列冲洗成功。</p>
<p>K_ERR_OBJ_PTR_NULL prio_mail_q 指针为空。</p>
<p>K_ERR_OBJ_INVALID prio_mail_q 指向的不是一个合法的邮箱队列。</p>
<h3 id="tos_prio_mail_q_pend">tos_prio_mail_q_pend</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_mail_q_pend</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">mail_buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="o">*</span><span class="n">mail_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试从邮箱队列中获取邮件。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>mail_buf</td>
<td>用来承载邮件内容的 buffer 地址</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>获取到的邮件长度</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>等待超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 从优先级邮箱队列获取邮件成功，mail_buf 中被写入邮件内容，msg_size 获取到的邮件长度。</p>
<p>K_ERR_PEND_NOWAIT 未能从优先级邮箱队列中获取到邮件，并且 timeout 参数为 TOS_TIME_NOWAIT（表示获取不到邮件时立即返回）。</p>
<p>K_ERR_PEND_SCHED_LOCKED 未能从优先级邮箱队列中获取到邮件，并且系统调度处于锁定状态。</p>
<p>K_ERR_PEND_TIMEOUT 在 timeout 超时范围内未能从优先级邮箱队列中获取到邮件。</p>
<p>K_ERR_PEND_DESTROY 尝试获取邮件的队列被销毁了（tos_prio_mail_q_destroy）。</p>
<h3 id="tos_prio_mail_q_post">tos_prio_mail_q_post</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_mail_q_post</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">mail_buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向优先级邮箱队列中放入一个邮件，并唤醒等待队列上的一个任务。如果有多个任务在此优先级邮箱队列的等待队列上，唤醒优先级最高的任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_buf</td>
<td>要放入优先级邮箱队列的邮件</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件长度</td>
</tr>
<tr>
<td>[in]</td>
<td>prio</td>
<td>邮件的优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向优先级邮箱队列中放入邮件成功。</p>
<p>K_ERR_RING_Q_FULL 优先级邮箱队列已满。</p>
<h3 id="tos_prio_mail_q_post_all">tos_prio_mail_q_post_all</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_mail_q_post_all</span><span class="p">(</span><span class="n">k_prio_mail_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_mail_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">mail_buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">mail_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向优先级邮箱队列中放入一个邮件，并唤醒等待队列上的所有任务。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_mail_q</td>
<td>优先级邮箱队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_buf</td>
<td>要放入优先级邮箱队列的邮件</td>
</tr>
<tr>
<td>[in]</td>
<td>mail_size</td>
<td>邮件长度</td>
</tr>
<tr>
<td>[in]</td>
<td>prio</td>
<td>邮件的优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 向优先级邮箱队列中放入邮件成功。</p>
<p>K_ERR_RING_Q_FULL 优先级邮箱队列已满。</p>
<h2 id="ring-queue">环形队列 ring queue</h2>
<h3 id="tos_ring_q_create">tos_ring_q_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_create</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个环形队列。环形队列提供了一种对数据进行先入先出管理的机制，可以作为上层数据结构或算法的底层数据容器。pool 由用户传入，pool 是一片大小为 (item_cnt * item_size) 的内存 buffer。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>pool</td>
<td>环形队列的 buffer 池</td>
</tr>
<tr>
<td>[in]</td>
<td>item_cnt</td>
<td>环形队列管理的元素的数量</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>环形队列管理的元素的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 环形队列创建成功。</p>
<h3 id="tos_ring_q_create_dyn">tos_ring_q_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_create</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个动态分配的环形队列。环形队列提供了一种对数据进行先入先出管理的机制，可以作为上层数据结构或算法的底层数据容器。内部的 pool 池由动态内存分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>item_cnt</td>
<td>环形队列管理的元素的数量</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>环形队列管理的元素的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 环形队列创建成功。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_ring_q_destroy">tos_ring_q_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_destroy</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个环形队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 销毁环形队列成功。</p>
<p>K_ERR_OBJ_INVALID ring_q 指向的不是一个合法的环形队列。</p>
<h3 id="tos_ring_q_destroy_dyn">tos_ring_q_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_destroy_dyn</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建的环形队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 销毁环形队列成功。</p>
<p>K_ERR_OBJ_INVALID ring_q 指向的不是一个合法的环形队列。</p>
<h3 id="tos_ring_q_enqueue">tos_ring_q_enqueue</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_enqueue</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">item</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向环形队列中放入一个元素。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>item</td>
<td>待入队的元素地址</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>待入队的元素大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 元素入队成功。</p>
<p>K_ERR_RING_Q_FULL 环形队列已满。</p>
<h3 id="tos_ring_q_dequeue">tos_ring_q_dequeue</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_dequeue</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">item</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="o">*</span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从环形队列中获取一个元素。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>item</td>
<td>承接出队元素的内存 buffer</td>
</tr>
<tr>
<td>[out]</td>
<td>item_size</td>
<td>出队的元素大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 元素出队成功。</p>
<p>K_ERR_RING_Q_EMPTY 环形队列已空。</p>
<h3 id="tos_ring_q_flush">tos_ring_q_flush</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_flush</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗环形队列（复位环形队列，丢弃环形队列中的所有元素）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 冲洗环形队列成功。</p>
<h3 id="tos_ring_q_is_empty">tos_ring_q_is_empty</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_is_empty</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断一个环形队列是否为空。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 环形队列为空。</p>
<p>K_FALSE 环形队列非空。</p>
<h3 id="tos_ring_q_is_full">tos_ring_q_is_full</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_ring_q_is_full</span><span class="p">(</span><span class="n">k_ring_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">ring_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断一个环形队列是否为满。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ring_q</td>
<td>环形队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 环形队列为满。</p>
<p>K_FALSE 环形队列非满。</p>
<h2 id="fifo">字符流先入先出队列 fifo</h2>
<h3 id="tos_chr_fifo_create">tos_chr_fifo_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_chr_fifo_create</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">,</span><span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="o">*</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个字符流先入先出队列。字符流先入先出队列的底层数据容器是环形队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>buffer</td>
<td>字符流先入先出队列内存池</td>
</tr>
<tr>
<td>[in]</td>
<td>size</td>
<td>字符流先入先出队列内存池大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL fifo 是空指针。</p>
<h3 id="tos_chr_fifo_create_dyn">tos_chr_fifo_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_chr_fifo_create</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">fifo_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>动态创建一个字符流先入先出队列（内部 buffer 动态分配）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>size</td>
<td>字符流先入先出队列内存池大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL chr_fifo 是空指针。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_chr_fifo_destroy">tos_chr_fifo_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_chr_fifo_destroy</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个字符流先入先出队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL chr_fifo 是空指针。</p>
<p>K_ERR_OBJ_INVALID chr_fifo 指向的不是一个合法的先入先出队列。</p>
<h3 id="tos_chr_fifo_destroy_dyn">tos_chr_fifo_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_chr_fifo_destroy_dyn</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建（tos_chr_fifo_create_dyn）的字符流先入先出队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 队列创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL chr_fifo 是空指针。</p>
<p>K_ERR_OBJ_INVALID chr_fifo 指向的不是一个合法的先入先出队列。</p>
<h3 id="tos_chr_fifo_push">tos_chr_fifo_push</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_chr_fifo_push</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">,</span><span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">data</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向字符流先入先出队列压入一个字符。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>data</td>
<td>压入的字符</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 字符压入成功。</p>
<p>K_ERR_FIFO_FULL 字符流先入先出队列已满。</p>
<h3 id="tos_chr_fifo_push_stream">tos_chr_fifo_push_stream</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_chr_fifo_push_stream</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">,</span><span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="o">*</span><span class="n">stream</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向字符流先入先出队列压入一个字符流。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>stream</td>
<td>压入的字符流</td>
</tr>
<tr>
<td>[in]</td>
<td>size</td>
<td>字符流长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>实际压入的字符流长度。</p>
<h3 id="tos_chr_fifo_pop">tos_chr_fifo_pop</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_chr_fifo_pop</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">,</span><span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="o">*</span><span class="n">out</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从字符流先入先出队列弹出一个字符。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>out</td>
<td>弹出的字符</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 字符弹出成功。</p>
<p>K_ERR_FIFO_EMPTY 字符流先入先出队列内存池已空。</p>
<h3 id="tos_chr_fifo_pop_stream">tos_chr_fifo_pop_stream</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_chr_fifo_pop_stream</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">fifo</span><span class="p">,</span><span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="o">*</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从字符流先入先出队列弹出一个字符流。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>stream</td>
<td>弹出的字符流</td>
</tr>
<tr>
<td>[in]</td>
<td>size</td>
<td>字符流长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>实际弹出的字符流长度。</p>
<h3 id="tos_chr_fifo_flush">tos_chr_fifo_flush</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_chr_fifo_flush</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗字符流先入先出队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>无</p>
<h3 id="tos_chr_fifo_is_empty">tos_chr_fifo_is_empty</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_chr_fifo_is_empty</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断字符流先入先出队列是否为空。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，fifo 不为空。</p>
<p>非 0 值，fifo 为空。</p>
<h3 id="tos_chr_fifo_is_full">tos_chr_fifo_is_full</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_chr_fifo_is_full</span><span class="p">(</span><span class="n">k_chr_fifo_t</span><span class="w"> </span><span class="o">*</span><span class="n">chr_fifo</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断字符流先入先出队列是否为满。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>chr_fifo</td>
<td>字符流先入先出队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，fifo 不为满。</p>
<p>非 0 值，fifo 为满。</p>
<h2 id="binary-heap">二项堆 binary heap</h2>
<h3 id="tos_bin_heap_create">tos_bin_heap_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bin_heap_create</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_bin_heap_cmp</span><span class="w"> </span><span class="n">cmp</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个二项堆。二项堆是实现优先级队列的底层数据结构。pool 由用户传入，pool 是一片大小为 (item_cnt * item_size) 的内存 buffer，cmp 是比较两个元素大小的比较函数。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>pool</td>
<td>二项堆的 buffer 池</td>
</tr>
<tr>
<td>[in]</td>
<td>item_cnt</td>
<td>二项堆管理的元素的数量</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>二项堆管理的元素的大小</td>
</tr>
<tr>
<td>[in]</td>
<td>cmp</td>
<td>比较两个二项堆元素大小的接口</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 二项堆创建成功。</p>
<h3 id="tos_bin_heap_create_dyn">tos_bin_heap_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bin_heap_create_dyn</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_bin_heap_cmp</span><span class="w"> </span><span class="n">cmp</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>动态创建一个二项堆。内部的 pool 池由动态内存分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>环形队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>item_cnt</td>
<td>此环形队列管理的元素的数量</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>从环形队列管理的元素的大小</td>
</tr>
<tr>
<td>[in]</td>
<td>cmp</td>
<td>比较两个二项堆元素大小的接口</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 二项堆创建成功。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_bin_heap_destroy">tos_bin_heap_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bin_heap_destroy</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个二项堆。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 销毁二项堆成功。</p>
<p>K_ERR_OBJ_INVALID bin_heap 指向的不是一个合法的二项堆。</p>
<h3 id="tos_bin_heap_destroy_dyn">tos_bin_heap_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bin_heap_destroy_dyn</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建的二项堆。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 销毁二项堆成功。</p>
<p>K_ERR_OBJ_INVALID bin_heap 指向的不是一个合法的二项堆。</p>
<h3 id="tos_bin_heap_push">tos_bin_heap_push</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bin_heap_push</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">item</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向二项堆中放入一个元素。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>item</td>
<td>待入堆的元素地址</td>
</tr>
<tr>
<td>[out]</td>
<td>item_size</td>
<td>待入堆的元素大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 元素入堆成功。</p>
<p>K_ERR_BIN_HEAP_FULL 二项堆已满。</p>
<h3 id="tos_bin_heap_pop">tos_bin_heap_pop</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bin_heap_pop</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">item</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="o">*</span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从二项堆中获取一个元素。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>item</td>
<td>承接出堆元素的内存 buffer</td>
</tr>
<tr>
<td>[out]</td>
<td>item_size</td>
<td>出堆的元素大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 元素出堆成功。</p>
<p>K_ERR_BIN_HEAP_EMPTY 二项堆已空。</p>
<h3 id="tos_bin_heap_flush">tos_bin_heap_flush</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bin_heap_flush</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗二项堆（复位二项堆，丢弃二项堆中的所有元素）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 冲洗二项堆成功。</p>
<h3 id="tos_bin_heap_is_empty">tos_bin_heap_is_empty</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_bin_heap_is_empty</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断一个二项堆是否为空。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 二项堆为空。</p>
<p>K_FALSE 二项堆非空。</p>
<h3 id="tos_bin_heap_is_full">tos_bin_heap_is_full</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_bin_heap_is_full</span><span class="p">(</span><span class="n">k_bin_heap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bin_heap</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断一个二项堆是否为满。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bin_heap</td>
<td>二项堆句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 二项堆为满。</p>
<p>K_FALSE 二项堆非满。</p>
<h2 id="priority-queue">优先级队列 priority queue</h2>
<h3 id="tos_prio_q_create">tos_prio_q_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_q_create</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">mgr_array</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">pool</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个优先级队列。优先级提供了一种对数据进行基于优先级管理的机制，每次出队的总是队列中优先级最高的元素，可以作为上层数据结构或算法的底层数据容器。pool 由用户传入，pool 是一片大小为 (item_cnt * item_size) 的内存 buffer，mgr_array 也是由用户传入，是一片大小为 TOS_PRIO_Q_MGR_ARRAY_SIZE(item_cnt) 的内存 buffer。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>mgr_array</td>
<td>优先级队列的内部管理数据池</td>
</tr>
<tr>
<td>[in]</td>
<td>pool</td>
<td>优先级队列的 buffer 池</td>
</tr>
<tr>
<td>[in]</td>
<td>item_cnt</td>
<td>优先级队列管理的元素的数量</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>优先级队列管理的元素的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级队列创建成功。</p>
<h3 id="tos_prio_q_create_dyn">tos_prio_q_create_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_q_create_dyn</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_cnt</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个动态分配的优先级队列。优先级提供了一种对数据进行基于优先级管理的机制，每次出队的总是队列中优先级最高的元素，可以作为上层数据结构或算法的底层数据容器。内部的 pool 池及管理数据池由动态内存分配。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>item_cnt</td>
<td>优先级队列管理的元素的数量</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>优先级队列管理的元素的大小</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 优先级队列创建成功。</p>
<p>K_ERR_OUT_OF_MEMORY 堆内存不足。</p>
<h3 id="tos_prio_q_destroy">tos_prio_q_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_q_destroy</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个优先级队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 销毁优先级队列成功。</p>
<p>K_ERR_OBJ_INVALID prio_q 指向的不是一个合法的优先级队列。</p>
<h3 id="tos_prio_q_destroy_dyn">tos_prio_q_destroy_dyn</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_q_destroy_dyn</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个动态创建的优先级队列。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 销毁优先级队列成功。</p>
<p>K_ERR_OBJ_INVALID prio_q 指向的不是一个合法的优先级队列。</p>
<h3 id="tos_prio_q_enqueue">tos_prio_q_enqueue</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_q_enqueue</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">item</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">item_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向优先级队列中放入一个元素。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>item</td>
<td>待入队的元素地址</td>
</tr>
<tr>
<td>[in]</td>
<td>item_size</td>
<td>待入队的元素大小</td>
</tr>
<tr>
<td>[in]</td>
<td>prio</td>
<td>入队元素的优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 元素入队成功。</p>
<p>K_ERR_PRIO_Q_FULL 优先级队列已满。</p>
<h3 id="tos_prio_q_dequeue">tos_prio_q_dequeue</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_q_dequeue</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">item</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="o">*</span><span class="n">item_size</span><span class="p">,</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从优先级队列中获取一个元素。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
<tr>
<td>[out]</td>
<td>item</td>
<td>承接出队元素的内存 buffer</td>
</tr>
<tr>
<td>[out]</td>
<td>item_size</td>
<td>出队的元素大小</td>
</tr>
<tr>
<td>[out]</td>
<td>prio</td>
<td>出队的元素的优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 元素出队成功。</p>
<p>K_ERR_PRIO_Q_EMPTY 优先级队列已空。</p>
<h3 id="tos_prio_q_flush">tos_prio_q_flush</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_prio_q_flush</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>冲洗优先级队列（复位优先级队列，丢弃优先级队列中的所有元素）。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 冲洗优先级队列成功。</p>
<h3 id="tos_prio_q_is_empty">tos_prio_q_is_empty</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_prio_q_is_empty</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断一个优先级队列是否为空。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 优先级队列为空。</p>
<p>K_FALSE 优先级队列非空。</p>
<h3 id="tos_prio_q_is_full">tos_prio_q_is_full</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_prio_q_is_full</span><span class="p">(</span><span class="n">k_prio_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">prio_q</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断一个优先级队列是否为满。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>prio_q</td>
<td>优先级队列句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 优先级队列为满。</p>
<p>K_FALSE 优先级队列非满。</p>
<h2 id="timer">定时器 timer</h2>
<h3 id="tos_timer_create">tos_timer_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_timer_create</span><span class="p">(</span><span class="n">k_timer_t</span><span class="w"> </span><span class="o">*</span><span class="n">tmr</span><span class="p">,</span>
<span class="w">                         </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">delay</span><span class="p">,</span>
<span class="w">                         </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">period</span><span class="p">,</span>
<span class="w">                         </span><span class="n">k_timer_callback_t</span><span class="w"> </span><span class="n">callback</span><span class="p">,</span>
<span class="w">                         </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">cb_arg</span><span class="p">,</span>
<span class="w">                         </span><span class="n">k_opt_t</span><span class="w"> </span><span class="n">opt</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个定时器。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tmr</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>delay</td>
<td>定时器延迟多久后执行</td>
</tr>
<tr>
<td>[in]</td>
<td>period</td>
<td>周期性 timer 的周期</td>
</tr>
<tr>
<td>[in]</td>
<td>callback</td>
<td>定时器回调</td>
</tr>
<tr>
<td>[in]</td>
<td>cb_arg</td>
<td>定时器回调参数</td>
</tr>
<tr>
<td>[in]</td>
<td>opt</td>
<td>选项</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>注意</strong></li>
</ul>
<p>opt 选项说明：</p>
<p>1、TOS_OPT_TIMER_ONESHOT</p>
<p>一次性定时器，创建定时器时传入此参数，表示该定时器是一次性的，只会执行一次。</p>
<p>2、TOS_OPT_TIMER_PERIODIC</p>
<p>周期性定时器，创建定时器时传入此参数，表示该定时器是周期性的，定时器到期后，会按 period 参数开启下一个周期。</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 定时器创建成功。</p>
<p>K_ERR_TIMER_INVALID_PERIOD 非法的 period 参数。</p>
<p>K_ERR_TIMER_INVALID_DELAY 非法的 delay 参数。</p>
<h3 id="tos_timer_destroy">tos_timer_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_timer_destroy</span><span class="p">(</span><span class="n">k_timer_t</span><span class="w"> </span><span class="o">*</span><span class="n">tmr</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个定时器。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tmr</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 定时器启动成功。</p>
<p>K_ERR_TIMER_INACTIVE 定时器并未被创建。</p>
<h3 id="tos_timer_start">tos_timer_start</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_timer_start</span><span class="p">(</span><span class="n">k_timer_t</span><span class="w"> </span><span class="o">*</span><span class="n">tmr</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>启动一个定时器。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tmr</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 定时器启动成功。</p>
<p>K_ERR_TIMER_INACTIVE 定时器并未被创建。</p>
<p>K_ERR_TIMER_INVALID_STATE 定时器状态非法。</p>
<h3 id="tos_timer_stop">tos_timer_stop</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_timer_stop</span><span class="p">(</span><span class="n">k_timer_t</span><span class="w"> </span><span class="o">*</span><span class="n">tmr</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>停止一个定时器。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tmr</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 停止定时器成功。</p>
<p>K_ERR_TIMER_INACTIVE 定时器并未被创建。</p>
<p>K_ERR_TIMER_STOPPED 定时器已经处于停止状态。</p>
<h3 id="tos_timer_delay_change">tos_timer_delay_change</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_timer_delay_change</span><span class="p">(</span><span class="n">k_timer_t</span><span class="w"> </span><span class="o">*</span><span class="n">tmr</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">delay</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>修改一个定时器的触发延时。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tmr</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>delay</td>
<td>修改后的触发延时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 修改定时器触发延时成功。</p>
<p>K_ERR_TIMER_INACTIVE 定时器并未被创建。</p>
<p>K_ERR_TIMER_RUNNING 定时器正处于运行状态（不允许修改运行中的定时器的触发延时参数）。</p>
<p>K_ERR_TIMER_INVALID_DELAY 非法的 delay 参数（试图将一个一次性定时器的 delay 参数修改为 0）。</p>
<h3 id="tos_timer_period_change">tos_timer_period_change</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_timer_period_change</span><span class="p">(</span><span class="n">k_timer_t</span><span class="w"> </span><span class="o">*</span><span class="n">tmr</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">perio</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>修改一个定时器的触发周期。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tmr</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>period</td>
<td>修改后的触发周期参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 修改定时器触发周期成功。</p>
<p>K_ERR_TIMER_INACTIVE 定时器并未被创建。</p>
<p>K_ERR_TIMER_RUNNING 定时器正处于运行状态（不允许修改运行中的定时器的触发延时参数）。</p>
<p>K_ERR_TIMER_INVALID_PERIOD 非法的 period 参数（试图将一个周期性定时器的 period 参数修改为 0）。</p>
<h2 id="stopwatch">计时表 stopwatch</h2>
<h3 id="tos_stopwatch_create">tos_stopwatch_create</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_stopwatch_create</span><span class="p">(</span><span class="n">k_stopwatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">stopwatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个计时表。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>计时表句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计时表创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL stopwatch 是空指针。</p>
<h3 id="tos_stopwatch_destroy">tos_stopwatch_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_stopwatch_destroy</span><span class="p">(</span><span class="n">k_stopwatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">stopwatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个计时表。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>计时表句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计时表销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL stopwatch 是空指针。</p>
<p>K_ERR_OBJ_INVALID stopwatch 指向的不是一个合法的计时表。</p>
<h3 id="tos_stopwatch_countdown">tos_stopwatch_countdown</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_stopwatch_countdown</span><span class="p">(</span><span class="n">k_stopwatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">stopwatch</span><span class="p">,</span><span class="w"> </span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">tick</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>开始计时，时间单位为系统滴答数。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>tick</td>
<td>计时的时间长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计时表启动成功。</p>
<h3 id="tos_stopwatch_countdown_ms">tos_stopwatch_countdown_ms</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_stopwatch_countdown_ms</span><span class="p">(</span><span class="n">k_stopwatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">stopwatch</span><span class="p">,</span><span class="w"> </span><span class="n">k_time_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>开始计时，时间单位为毫秒。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>计时的时间长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 计时表启动成功。</p>
<h3 id="tos_stopwatch_delay">tos_stopwatch_delay</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_stopwatch_delay</span><span class="p">(</span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">tick</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>利用计时表进行一次延时，时间单位为系统滴答数。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>tick</td>
<td>延迟的时间长度</td>
</tr>
</tbody>
</table>
<h3 id="tos_stopwatch_delay_ms">tos_stopwatch_delay_ms</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_stopwatch_delay_ms</span><span class="p">(</span><span class="n">k_time_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>利用计时表进行一次延时，时间单位为毫秒。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>延迟的时间长度</td>
</tr>
</tbody>
</table>
<h3 id="tos_stopwatch_remain">tos_stopwatch_remain</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_tick_t</span><span class="w"> </span><span class="nf">tos_stopwatch_remain</span><span class="p">(</span><span class="n">k_stopwatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">stopwatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>返回计时表剩余的时间，时间单位为系统滴答数，如果计时已到则返回 0。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>计时表剩余时间。</p>
<h3 id="tos_stopwatch_remain_ms">tos_stopwatch_remain_ms</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_tick_t</span><span class="w"> </span><span class="nf">tos_stopwatch_remain_ms</span><span class="p">(</span><span class="n">k_stopwatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">stopwatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>返回计时表剩余的时间，时间单位为毫秒，如果计时已到则返回 0。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>计时表剩余时间。</p>
<h3 id="tos_stopwatch_is_expired">tos_stopwatch_is_expired</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_stopwatch_is_expired</span><span class="p">(</span><span class="n">k_stopwatch_t</span><span class="w"> </span><span class="o">*</span><span class="n">stopwatch</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>返回计时表是否已超时。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>stopwatch</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 计时表已超时。</p>
<p>K_FALSE 计时表未超时。</p>
<h2 id="bitmap">位图 bitmap</h2>
<h3 id="tos_bitmap_create_empty">tos_bitmap_create_empty</h3>
<div class="highlight"><pre><span></span><code><span class="n">__API__</span><span class="w"> </span><span class="n">k_err_t</span><span class="w"> </span><span class="n">tos_bitmap_create_empty</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">,</span><span class="w"> </span><span class="n">k_bmtbl_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap_tbl</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">bit_max</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个全 0 的位图。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>位图句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>bitmap_tbl</td>
<td>位图所需的存储表。</td>
</tr>
<tr>
<td>[in]</td>
<td>bit_max</td>
<td>位图中可记录的最大的 bit 位长度</td>
</tr>
</tbody>
</table>
<ul>
<li>注意</li>
</ul>
<p>bitmap_tbl 是由用户传入的一片内存区域，其长度由 TOS_BITMAP_SIZE 计算，对于最大的 bit 位长度为 bit_max 的位图存储表来说，其长度为 TOS_BITMAP_SIZE(bit_max)，那么用户可以定义一个 k_bmtbl_t bitmap_tbl[TOS_BITMAP_SIZE(bit_max)]，bitmap_tbl 作为此接口的第二个入参。</p>
<ul>
<li>返回值**</li>
</ul>
<p>K_ERR_NONE 计时表创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL bitmap 或 bitmap_tbl 是空指针。</p>
<h3 id="tos_bitmap_create_full">tos_bitmap_create_full</h3>
<div class="highlight"><pre><span></span><code><span class="n">__API__</span><span class="w"> </span><span class="n">k_err_t</span><span class="w"> </span><span class="n">tos_bitmap_create_full</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">,</span><span class="w"> </span><span class="n">k_bmtbl_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap_tbl</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">bit_max</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个全 1 的位图。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>位图句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>bitmap_tbl</td>
<td>位图所需的存储表。</td>
</tr>
<tr>
<td>[in]</td>
<td>bit_max</td>
<td>位图中可记录的最大的 bit 位长度</td>
</tr>
</tbody>
</table>
<ul>
<li>注意</li>
</ul>
<p>bitmap_tbl 是由用户传入的一片内存区域，其长度由 TOS_BITMAP_SIZE 计算，对于最大的 bit 位长度为 bit_max 的位图存储表来说，其长度为 TOS_BITMAP_SIZE(bit_max)，那么用户可以定义一个 k_bmtbl_t bitmap_tbl[TOS_BITMAP_SIZE(bit_max)]，bitmap_tbl 作为此接口的第二个入参。</p>
<ul>
<li>返回值**</li>
</ul>
<p>K_ERR_NONE 计时表创建成功。</p>
<p>K_ERR_OBJ_PTR_NULL bitmap 或 bitmap_tbl 是空指针。</p>
<h3 id="tos_bitmap_destroy">tos_bitmap_destroy</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bitmap_destroy</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁一个位图。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>位图句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 位图销毁成功。</p>
<p>K_ERR_OBJ_PTR_NULL bitmap 是空指针。</p>
<p>K_ERR_OBJ_INVALID bitmap 指向的不是一个合法的位图。</p>
<h3 id="tos_bitmap_set">tos_bitmap_set</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bitmap_set</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">bit</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>设置一个 bit 位，即将此 bit 位标记为 1。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>位图句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>bit</td>
<td>要设置的 bit 位</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE bit 位设置成功。</p>
<p>K_ERR_BITMAP_EXCEED bit 超出了 bitmap 可以记录的范围。</p>
<h3 id="tos_bitmap_reset">tos_bitmap_reset</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bitmap_reset</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">bit</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>复位一个 bit 位，即将此 bit 位标记为 0。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>位图句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>bit</td>
<td>要设置的 bit 位</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE bit 位复位成功。</p>
<p>K_ERR_BITMAP_EXCEED bit 超出了 bitmap 可以记录的范围。</p>
<h3 id="tos_bitmap_is_set">tos_bitmap_is_set</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bitmap_is_set</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">bit</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断某 bit 位是否处于设置状态，也即是否为 1。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>位图句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>bit</td>
<td>bit 位</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 该位被设置，即为 1。</p>
<p>K_FALSE 该位未被设置，即为 0。</p>
<p>K_ERR_BITMAP_EXCEED bit 超出了 bitmap 可以记录的范围。</p>
<h3 id="tos_bitmap_is_reset">tos_bitmap_is_reset</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_bitmap_is_reset</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">bit</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>判断某 bit 位是否处于复位状态，也即是否为 0。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>位图句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>bit</td>
<td>bit 位</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_TRUE 该位被复位，即为 0。</p>
<p>K_FALSE 该位未被设置，即为 1。</p>
<h3 id="tos_bitmap_lsb">tos_bitmap_lsb</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_bitmap_lsb</span><span class="p">(</span><span class="n">k_bitmap_t</span><span class="w"> </span><span class="o">*</span><span class="n">bitmap</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取位图的最低有效位，也即最低的被设置为 1 的位。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>bitmap</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>位图的最低有效位。</p>
<h2 id="_5">时间管理</h2>
<h3 id="tos_systick_get">tos_systick_get</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_tick_t</span><span class="w"> </span><span class="nf">tos_systick_get</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取系统时钟滴答数。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>系统自启动为止到目前为止的时钟滴答数。</p>
<h3 id="tos_systick_set">tos_systick_set</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_systick_set</span><span class="p">(</span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">tick</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>设置系统时钟滴答数。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tick</td>
<td>系统时钟滴答数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>无</p>
<h3 id="tos_tick2millisec">tos_tick2millisec</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_time_t</span><span class="w"> </span><span class="nf">tos_tick2millisec</span><span class="p">(</span><span class="n">k_tick_t</span><span class="w"> </span><span class="n">tick</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>系统时钟滴答数转化为毫秒。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>tick</td>
<td>系统时钟滴答数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>毫秒数。</p>
<h3 id="tos_millisec2tick">tos_millisec2tick</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_tick_t</span><span class="w"> </span><span class="nf">tos_millisec2tick</span><span class="p">(</span><span class="n">k_time_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>毫秒转化为系统时钟滴答数。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>毫秒数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>系统时钟滴答数。</p>
<h3 id="tos_sleep_ms">tos_sleep_ms</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sleep_ms</span><span class="p">(</span><span class="n">k_time_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>睡眠当前任务，以毫秒为单位。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>任务睡眠毫秒数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 睡眠成功。</p>
<p>K_ERR_DELAY_ZERO 毫秒数为 0。</p>
<h3 id="tos_sleep_hmsm">tos_sleep_hmsm</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_sleep_hmsm</span><span class="p">(</span><span class="n">k_time_t</span><span class="w"> </span><span class="n">hour</span><span class="p">,</span><span class="w"> </span><span class="n">k_time_t</span><span class="w"> </span><span class="n">minute</span><span class="p">,</span><span class="w"> </span><span class="n">k_time_t</span><span class="w"> </span><span class="n">second</span><span class="p">,</span><span class="w"> </span><span class="n">k_time_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>睡眠当前任务，睡眠时长以特定的时分秒毫秒度量。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>hour</td>
<td>小时数</td>
</tr>
<tr>
<td>[in]</td>
<td>minute</td>
<td>分钟数</td>
</tr>
<tr>
<td>[in]</td>
<td>second</td>
<td>秒数</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>毫秒数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 睡眠成功。</p>
<p>K_ERR_DELAY_ZERO 毫秒数为 0。</p>
<h2 id="_6">功耗管理</h2>
<h3 id="tos_pm_cpu_lpwr_mode_set">tos_pm_cpu_lpwr_mode_set</h3>
<div class="highlight"><pre><span></span><code><span class="n">k_err_t</span><span class="w"> </span><span class="nf">tos_pm_cpu_lpwr_mode_set</span><span class="p">(</span><span class="n">k_cpu_lpwr_mode_t</span><span class="w"> </span><span class="n">cpu_lpwr_mode</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>设置 CPU 的低功耗模式。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>cpu_lpwr_mode</td>
<td>CPU 的低功耗模式</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_PM_WKUP_SOURCE_NOT_INSTALL 对应低功耗模式下的唤醒源没有安装。</p>
<p>K_ERR_NONE 低功耗模式设置成功。</p>
<h3 id="tos_pm_device_register">tos_pm_device_register</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_pm_device_register</span><span class="p">(</span><span class="n">k_pm_device_t</span><span class="w"> </span><span class="o">*</span><span class="n">device</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>注册一个低功耗管理设备。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>device</td>
<td>低功耗管理设备句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_NONE 注册成功。</p>
<p>K_ERR_OBJ_PTR_NULL device 为空。</p>
<p>K_ERR_PM_DEVICE_ALREADY_REG 设备已注册过。</p>
<p>K_ERR_PM_DEVICE_OVERFLOW 注册设备数量太多。</p>
<h3 id="tos_tickless_wkup_alarm_install">tos_tickless_wkup_alarm_install</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="nf">tos_tickless_wkup_alarm_install</span><span class="p">(</span><span class="n">k_cpu_lpwr_mode_t</span><span class="w"> </span><span class="n">mode</span><span class="p">,</span><span class="w"> </span><span class="n">k_tickless_wkup_alarm_t</span><span class="w"> </span><span class="o">*</span><span class="n">wkup_alarm</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>安装一个低功耗模式下的唤醒时钟。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mode</td>
<td>低功耗模式</td>
</tr>
<tr>
<td>[in]</td>
<td>wkup_alarm</td>
<td>唤醒时钟</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>无</p>
<h3 id="tos_tickless_wkup_alarm_init">tos_tickless_wkup_alarm_init</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tickless_wkup_alarm_init</span><span class="p">(</span><span class="n">k_cpu_lpwr_mode_t</span><span class="w"> </span><span class="n">mode</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>初始化特定低功耗模式下的唤醒时钟。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mode</td>
<td>低功耗模式</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>K_ERR_TICKLESS_WKUP_ALARM_NOT_INSTALLED 对应低功耗模式的唤醒闹钟没有被安装</p>
<p>K_ERR_TICKLESS_WKUP_ALARM_NO_INIT 对应低功耗模式的唤醒闹钟没有初始化函数</p>
<h1 id="api_1">组件 API</h1>
<h2 id="mqtt">MQTT 端云对接</h2>
<h3 id="tos_mqtt_connect">tos_mqtt_connect</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_mqtt_connect</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">host</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">port</span><span class="p">,</span><span class="w"> </span><span class="n">mqtt_con_param_t</span><span class="w"> </span><span class="o">*</span><span class="n">param</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>连接 MQTT 服务器。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>host</td>
<td>服务器 IP 地址或域名</td>
</tr>
<tr>
<td>[in]</td>
<td>port</td>
<td>服务器端口</td>
</tr>
<tr>
<td>[in]</td>
<td>param</td>
<td>连接参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，返回 socket fd。</p>
<p>失败，返回 -1。</p>
<h3 id="tos_mqtt_publish">tos_mqtt_publish</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_mqtt_publish</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">,</span><span class="w"> </span><span class="n">mqtt_pub_param_t</span><span class="w"> </span><span class="o">*</span><span class="n">param</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>发布 MQTT 消息</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket fd，由 tos_mqtt_connect 获取。</td>
</tr>
<tr>
<td>[in]</td>
<td>param</td>
<td>消息发布参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，发布成功。</p>
<p>-1，发布失败。</p>
<h3 id="tos_mqtt_subscribe">tos_mqtt_subscribe</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_mqtt_subscribe</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">,</span><span class="w"> </span><span class="n">mqtt_sub_param_t</span><span class="w"> </span><span class="o">*</span><span class="n">param</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>订阅 MQTT 消息</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket fd，由 tos_mqtt_connect 获取。</td>
</tr>
<tr>
<td>[in]</td>
<td>param</td>
<td>消息订阅参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，订阅成功。</p>
<p>-1，订阅失败。</p>
<h3 id="tos_mqtt_receive">tos_mqtt_receive</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_mqtt_receive</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">topic</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">topic_len</span><span class="p">,</span><span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">payload</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">payload_len</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>收取 MQTT 消息</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[out]</td>
<td>topic</td>
<td>收取到的 MQTT topic</td>
</tr>
<tr>
<td>[in]</td>
<td>topic_len</td>
<td>MQTT topic buffer 长度</td>
</tr>
<tr>
<td>[out]</td>
<td>payload</td>
<td>收取到的 payload</td>
</tr>
<tr>
<td>[in]</td>
<td>payload_len</td>
<td>payload buffer 长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，返回收取到的 payload 长度。</p>
<p>失败，返回 -1。</p>
<h2 id="cmsis">CMSIS 适配层</h2>
<h3 id="oskernelstart">osKernelStart</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osKernelStart</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>启动内核</p>
<ul>
<li>
<p><strong>参数解释</strong>
  无</p>
</li>
<li>
<p><strong>返回值</strong>
  osOK，返回成功。</p>
</li>
</ul>
<p>osErrorOS，返回失败。</p>
<h3 id="oskernelinitialize">osKernelInitialize</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osKernelInitialize</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>初始化内核</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="oskernelrunning">osKernelRunning</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int32_t</span><span class="w"> </span><span class="nf">osKernelRunning</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>返回内核是否正在运行</p>
<ul>
<li>
<p><strong>参数解释</strong>
  无</p>
</li>
<li>
<p><strong>返回值</strong>
  0，内核不在运行。</p>
</li>
</ul>
<p>非 0，内核正在运行。</p>
<h3 id="oskernelsystick">osKernelSysTick</h3>
<div class="highlight"><pre><span></span><code><span class="kt">uint32_t</span><span class="w"> </span><span class="nf">osKernelSysTick</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取系统时钟滴答数</p>
<ul>
<li>
<p><strong>参数解释</strong>
  无</p>
</li>
<li>
<p><strong>返回值</strong>
  系统自启动开始到目前的时钟滴答数。</p>
</li>
</ul>
<h3 id="osthreadcreate">osThreadCreate</h3>
<div class="highlight"><pre><span></span><code><span class="n">osThreadId</span><span class="w"> </span><span class="nf">osThreadCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osThreadDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">thread_def</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">argument</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建任务</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>thread_def</td>
<td>任务初始化参数</td>
</tr>
<tr>
<td>[in]</td>
<td>argument</td>
<td>传递给任务入参</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回创建的任务句柄。</p>
<p>失败，返回 NULL。</p>
<h3 id="osthreadgetid">osThreadGetId</h3>
<div class="highlight"><pre><span></span><code><span class="n">osThreadId</span><span class="w"> </span><span class="nf">osThreadGetId</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取当前任务句柄</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>当前任务句柄。</p>
<h3 id="osthreadterminate">osThreadTerminate</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osThreadTerminate</span><span class="p">(</span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>终止任务运行并删除任务</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>thread_id</td>
<td>任务句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="osthreadsetpriority">osThreadSetPriority</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osThreadSetPriority</span><span class="p">(</span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">,</span><span class="w"> </span><span class="n">osPriority</span><span class="w"> </span><span class="n">priority</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>设置任务优先级</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>thread_id</td>
<td>任务句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>priority</td>
<td>优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="osthreadgetpriority">osThreadGetPriority</h3>
<div class="highlight"><pre><span></span><code><span class="n">osPriority</span><span class="w"> </span><span class="nf">osThreadGetPriority</span><span class="p">(</span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>获取任务优先级</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>thread_id</td>
<td>任务句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>任务优先级。</p>
<h3 id="osdelay">osDelay</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osDelay</span><span class="p">(</span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>睡眠当前任务，以毫秒为单位。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>睡眠时间毫秒数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="ostimercreate">osTimerCreate</h3>
<div class="highlight"><pre><span></span><code><span class="n">osTimerId</span><span class="w"> </span><span class="nf">osTimerCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osTimerDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">timer_def</span><span class="p">,</span><span class="w"> </span><span class="n">os_timer_type</span><span class="w"> </span><span class="n">type</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">argument</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个定时器。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>timer_def</td>
<td>定时器初始化参数</td>
</tr>
<tr>
<td>[in]</td>
<td>type</td>
<td>定时器类型</td>
</tr>
<tr>
<td>[in]</td>
<td>argument</td>
<td>定时器回调入参</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回创建的定时器句柄。</p>
<p>失败，返回 NULL。</p>
<h3 id="ostimerstart">osTimerStart</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osTimerStart</span><span class="p">(</span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>启动定时器</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>timer_id</td>
<td>定时器句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>执行延迟参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="ostimerstop">osTimerStop</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osTimerStop</span><span class="p">(</span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>停止定时器</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>timer_id</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="ostimerdelete">osTimerDelete</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osTimerDelete</span><span class="p">(</span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁定时器</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>timer_id</td>
<td>定时器句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="osmutexcreate">osMutexCreate</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMutexCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osMutexDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">mutex_def</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建互斥量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex_def</td>
<td>互斥量初始化参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回创建的互斥量句柄。</p>
<p>失败，返回 NULL。</p>
<h3 id="osmutexwait">osMutexWait</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMutexWait</span><span class="p">(</span><span class="n">osMutexId</span><span class="w"> </span><span class="n">mutex_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>尝试获取一个互斥量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex_id</td>
<td>互斥量句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="osmutexrelease">osMutexRelease</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMutexRelease</span><span class="p">(</span><span class="n">osMutexId</span><span class="w"> </span><span class="n">mutex_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放互斥量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex_id</td>
<td>互斥量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="osmutexdelete">osMutexDelete</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMutexDelete</span><span class="p">(</span><span class="n">osMutexId</span><span class="w"> </span><span class="n">mutex_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁互斥量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>mutex_id</td>
<td>互斥量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="ossemaphorecreate">osSemaphoreCreate</h3>
<div class="highlight"><pre><span></span><code><span class="n">osSemaphoreId</span><span class="w"> </span><span class="nf">osSemaphoreCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osSemaphoreDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">semaphore_def</span><span class="p">,</span><span class="w"> </span><span class="kt">int32_t</span><span class="w"> </span><span class="n">count</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个信号量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>semaphore_def</td>
<td>信号量初始化参数</td>
</tr>
<tr>
<td>[in]</td>
<td>count</td>
<td>信号量初始值</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回创建的信号量句柄。</p>
<p>失败，返回 NULL。</p>
<h3 id="ossemaphorewait">osSemaphoreWait</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int32_t</span><span class="w"> </span><span class="nf">osSemaphoreWait</span><span class="p">(</span><span class="n">osSemaphoreId</span><span class="w"> </span><span class="n">semaphore_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>等待一个信号量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>semaphore_id</td>
<td>信号量句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回信号量可用的资源数。</p>
<p>失败，返回 -1。</p>
<h3 id="ossemaphorerelease">osSemaphoreRelease</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osSemaphoreRelease</span><span class="p">(</span><span class="n">osSemaphoreId</span><span class="w"> </span><span class="n">semaphore_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放信号量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>semaphore_id</td>
<td>信号量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="ossemaphoredelete">osSemaphoreDelete</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osSemaphoreDelete</span><span class="p">(</span><span class="n">osSemaphoreId</span><span class="w"> </span><span class="n">semaphore_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>销毁信号量</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>semaphore_id</td>
<td>信号量句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="ospoolcreate">osPoolCreate</h3>
<div class="highlight"><pre><span></span><code><span class="n">osPoolId</span><span class="w"> </span><span class="nf">osPoolCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osPoolDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">pool_def</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个内存池</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>pool_def</td>
<td>内存池初始化参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回创建的内存池句柄。</p>
<p>失败，返回 NULL。</p>
<h3 id="ospoolalloc">osPoolAlloc</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">osPoolAlloc</span><span class="p">(</span><span class="n">osPoolId</span><span class="w"> </span><span class="n">pool_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从内存池中获取一个内存块</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>pool_id</td>
<td>内存池句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回分配到的内存块起始地址。</p>
<p>失败，返回 NULL。</p>
<h3 id="ospoolcalloc">osPoolCAlloc</h3>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">osPoolCAlloc</span><span class="p">(</span><span class="n">osPoolId</span><span class="w"> </span><span class="n">pool_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从内存池中获取一个内存块，并将此内存块清空为 0。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>pool_id</td>
<td>内存池句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回分配到的内存块起始地址。</p>
<p>失败，返回 NULL。</p>
<h3 id="ospoolfree">osPoolFree</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osPoolFree</span><span class="p">(</span><span class="n">osPoolId</span><span class="w"> </span><span class="n">pool_id</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">block</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>释放一个内存块</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>pool_id</td>
<td>内存池句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>block</td>
<td>内存块起始地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="osmessagecreate">osMessageCreate</h3>
<div class="highlight"><pre><span></span><code><span class="n">osMessageQId</span><span class="w"> </span><span class="nf">osMessageCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osMessageQDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">queue_def</span><span class="p">,</span><span class="w"> </span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>创建一个队列</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>queue_def</td>
<td>队列初始化参数</td>
</tr>
<tr>
<td>[in]</td>
<td>thread_id</td>
<td>任务句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回创建的队列句柄。</p>
<p>失败，返回 NULL。</p>
<h3 id="osmessageput">osMessagePut</h3>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMessagePut</span><span class="p">(</span><span class="n">osMessageQId</span><span class="w"> </span><span class="n">queue_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">info</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向队列中放置一个消息</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>queue_id</td>
<td>队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>info</td>
<td>要放置的消息体</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>osOK，返回成功。</p>
<p>osErrorOS，返回失败。</p>
<h3 id="osmessageget">osMessageGet</h3>
<div class="highlight"><pre><span></span><code><span class="n">osEvent</span><span class="w"> </span><span class="nf">osMessageGet</span><span class="p">(</span><span class="n">osMessageQId</span><span class="w"> </span><span class="n">queue_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从内存池中获取一个消息</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>queue_id</td>
<td>队列句柄</td>
</tr>
<tr>
<td>[in]</td>
<td>millisec</td>
<td>超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>一个包含了返回状态的 osEvent 信息结构体。</p>
<h1 id="api_2">网络 API</h1>
<h2 id="sal">sal 模组联网接口</h2>
<h3 id="tos_sal_module_register">tos_sal_module_register</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_register</span><span class="p">(</span><span class="n">sal_module_t</span><span class="w"> </span><span class="o">*</span><span class="n">module</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>注册一个联网模组</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>module</td>
<td>联网模组句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_sal_module_init">tos_sal_module_init</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>初始化模组</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_sal_module_parse_domain">tos_sal_module_parse_domain</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_parse_domain</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">host_name</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">host_ip</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>域名解析，将一个域名转换为 IP 地址。</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>host_name</td>
<td>待解析的域名</td>
</tr>
<tr>
<td>[out]</td>
<td>host_ip</td>
<td>解析后的 IP 地址</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_sal_module_connect">tos_sal_module_connect</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_connect</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">ip</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">port</span><span class="p">,</span><span class="w"> </span><span class="n">sal_proto_t</span><span class="w"> </span><span class="n">proto</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向远端发起连接</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>ip</td>
<td>IP 地址</td>
</tr>
<tr>
<td>[in]</td>
<td>port</td>
<td>端口</td>
</tr>
<tr>
<td>[in]</td>
<td>proto</td>
<td>TCP/UDP 协议</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>成功，则返回连接的 socket id。</p>
<p>失败，返回 -1。</p>
<h3 id="tos_sal_module_send">tos_sal_module_send</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_send</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向远端发送数据（TCP 协议栈）</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket id(由 tos_sal_module_connect 获取)</td>
</tr>
<tr>
<td>[in]</td>
<td>buf</td>
<td>发送的数据起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>发送的数据长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong>
  发送的数据长度。</li>
</ul>
<h3 id="tos_sal_module_recv">tos_sal_module_recv</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_recv</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从远端读取数据（TCP 协议栈）</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket id（由 tos_sal_module_connect 获取）</td>
</tr>
<tr>
<td>[out]</td>
<td>buf</td>
<td>接收数据 buffer</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>接收数据 buffer 长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong>
  实际接收到的数据长度。</li>
</ul>
<h3 id="tos_sal_module_recv_timeout">tos_sal_module_recv_timeout</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_recv_timeout</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从远端接收数据（TCP 协议栈）</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket id（由 tos_sal_module_connect 获取）</td>
</tr>
<tr>
<td>[in]</td>
<td>buf</td>
<td>数据起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>数据长度</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong>
  实际接收到的数据长度。</li>
</ul>
<h3 id="tos_sal_module_sendto">tos_sal_module_sendto</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_sendto</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">ip</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">port</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>向远端发送数据（UDP 协议栈）</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket id（由 tos_sal_module_connect 获取）</td>
</tr>
<tr>
<td>[in]</td>
<td>ip</td>
<td>IP 地址</td>
</tr>
<tr>
<td>[in]</td>
<td>port</td>
<td>端口</td>
</tr>
<tr>
<td>[in]</td>
<td>buf</td>
<td>待发送数据起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>待发送数据长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong>
  发送的数据长度。</li>
</ul>
<h3 id="tos_sal_module_recvfrom">tos_sal_module_recvfrom</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_recvfrom</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">ip</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">port</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>从远端接收数据（UDP 协议栈）</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket id（由 tos_sal_module_connect 获取）</td>
</tr>
<tr>
<td>[in]</td>
<td>ip</td>
<td>IP 地址</td>
</tr>
<tr>
<td>[in]</td>
<td>port</td>
<td>端口</td>
</tr>
<tr>
<td>[in]</td>
<td>buf</td>
<td>接收数据 buffer 起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>接收数据 buffer 长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong>
  实际接收到的数据长度。</li>
</ul>
<h3 id="tos_sal_module_close">tos_sal_module_close</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_sal_module_close</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">sock</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>关闭与远端的连接</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>sock</td>
<td>socket id（由 tos_sal_module_connect 获取）</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h2 id="lora">lora 模组联网接口</h2>
<h3 id="tos_lora_module_register">tos_lora_module_register</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_lora_module_register</span><span class="p">(</span><span class="n">lora_module_t</span><span class="w"> </span><span class="o">*</span><span class="n">module</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>注册一个 lora 模组</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>module</td>
<td>lora 模组句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_lora_module_init">tos_lora_module_init</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_lora_module_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>初始化 lora 模组</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_lora_module_join">tos_lora_module_join</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_lora_module_join</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>加入 lora 网关</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_lora_module_send">tos_lora_module_send</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_lora_module_send</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>通过 lora 模组发送数据</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>buf</td>
<td>要发送的数据起始地址</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>要发送的数据长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_lora_module_recv">tos_lora_module_recv</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_lora_module_recv</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>通过 lora 模组接收数据</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[out]</td>
<td>buf</td>
<td>接收数据的 buffer 地址</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>buffer 长度</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_lora_module_recv_timeout">tos_lora_module_recv_timeout</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_lora_module_recv_timeout</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">len</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>通过 lora 模组接收数据</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>buf</td>
<td>接收数据的 buffer 地址</td>
</tr>
<tr>
<td>[in]</td>
<td>len</td>
<td>buffer 长度</td>
</tr>
<tr>
<td>[in]</td>
<td>timeout</td>
<td>超时参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_lora_module_close">tos_lora_module_close</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_lora_module_close</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>关闭 lora 模组</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h2 id="_7">腾讯定制固件模组联网接口</h2>
<h3 id="tos_tf_module_register">tos_tf_module_register</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_register</span><span class="p">(</span><span class="n">tencent_firmware_module_t</span><span class="w"> </span><span class="o">*</span><span class="n">module</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>注册一个腾讯定制固件模组</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>module</td>
<td>腾讯定制固件模组句柄</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_init">tos_tf_module_init</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>初始化腾讯定制固件模组</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_info_set">tos_tf_module_info_set</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_info_set</span><span class="p">(</span><span class="n">device_info_t</span><span class="w"> </span><span class="o">*</span><span class="n">info</span><span class="p">,</span><span class="w"> </span><span class="n">tls_mode_t</span><span class="w"> </span><span class="n">tls_mode</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>设置腾讯定制固件模组设备信息</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>device_info_t</td>
<td>腾讯定制固件模组设备信息描述结构体</td>
</tr>
<tr>
<td>[in]</td>
<td>tls_mode</td>
<td>tls 校验模式</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_mqtt_conn">tos_tf_module_mqtt_conn</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_mqtt_conn</span><span class="p">(</span><span class="n">mqtt_param_t</span><span class="w"> </span><span class="n">init_params</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>通过腾讯定制固件模组发起 MQTT 连接</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>init_params</td>
<td>MQTT 连接参数</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_mqtt_discon">tos_tf_module_mqtt_discon</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_mqtt_discon</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>断开腾讯定制固件模组的 MQTT 连接</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<p>无</p>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_mqtt_pub">tos_tf_module_mqtt_pub</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_mqtt_pub</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">topic</span><span class="p">,</span><span class="w"> </span><span class="n">qos_t</span><span class="w"> </span><span class="n">qos</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">payload</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>发布主题</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>topic</td>
<td>主题</td>
</tr>
<tr>
<td>[in]</td>
<td>qos</td>
<td>qos</td>
</tr>
<tr>
<td>[in]</td>
<td>payload</td>
<td>主题的消息负载</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_mqtt_publ">tos_tf_module_mqtt_publ</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_mqtt_publ</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">topic</span><span class="p">,</span><span class="w"> </span><span class="n">qos_t</span><span class="w"> </span><span class="n">qos</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">payload</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>发布长消息负载（&gt; 200）主题</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>topic</td>
<td>主题</td>
</tr>
<tr>
<td>[in]</td>
<td>qos</td>
<td>qos</td>
</tr>
<tr>
<td>[in]</td>
<td>payload</td>
<td>主题的消息负载</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_mqtt_sub">tos_tf_module_mqtt_sub</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_mqtt_sub</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">topic</span><span class="p">,</span><span class="w"> </span><span class="n">qos_t</span><span class="w"> </span><span class="n">qos</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>订阅主题</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>topic</td>
<td>主题</td>
</tr>
<tr>
<td>[in]</td>
<td>qos</td>
<td>qos</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_mqtt_unsub">tos_tf_module_mqtt_unsub</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_mqtt_unsub</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">topic</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>取消订阅主题</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>topic</td>
<td>主题</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_mqtt_state">tos_tf_module_mqtt_state</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_mqtt_state</span><span class="p">(</span><span class="n">mqtt_state_t</span><span class="w"> </span><span class="o">*</span><span class="n">state</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>查询 MQTT 连接状态</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[out]</td>
<td>state</td>
<td>连接状态</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>
<h3 id="tos_tf_module_debug_level_set">tos_tf_module_debug_level_set</h3>
<div class="highlight"><pre><span></span><code><span class="kt">int</span><span class="w"> </span><span class="nf">tos_tf_module_debug_level_set</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">log_level</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><strong>功能描述</strong></li>
</ul>
<p>设置模组调试日志级别</p>
<ul>
<li><strong>参数解释</strong></li>
</ul>
<table>
<thead>
<tr>
<th>IN/OUT</th>
<th>参数名</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>[in]</td>
<td>log_level</td>
<td>调试日志级别</td>
</tr>
</tbody>
</table>
<ul>
<li><strong>返回值</strong></li>
</ul>
<p>0，返回成功。</p>
<p>-1，返回失败。</p>





                
              </article>
            </div>
          
          
        </div>
        
          <button type="button" class="md-top md-icon" data-md-component="top" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg>
            回到页面顶部
          </button>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
    <div class="md-copyright__highlight">
      Copyright &copy; 2023 TobudOS
    </div>
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    <script id="__config" type="application/json">{"base": "../..", "features": ["content.action.edit", "content.action.view", "content.code.annotate", "content.tooltips", "navigation.indexes", "navigation.sections", "navigation.tabs", "navigation.top", "navigation.tracking", "search.highlight", "search.share", "search.suggest", "toc.follow"], "search": "../../assets/javascripts/workers/search.74e28a9f.min.js", "translations": {"clipboard.copied": "\u5df2\u590d\u5236", "clipboard.copy": "\u590d\u5236", "search.result.more.one": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.more.other": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 # \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.term.missing": "\u7f3a\u5c11", "select.version": "\u9009\u62e9\u5f53\u524d\u7248\u672c"}}</script>
    
    
      <script src="../../assets/javascripts/bundle.220ee61c.min.js"></script>
      
    
  </body>
</html>